From 9a55b8c9af871b1e58b7f4f367b7c26fc53ab543 Mon Sep 17 00:00:00 2001 From: "asvitkine@chromium.org" Date: Thu, 17 May 2012 20:53:08 +0000 Subject: [PATCH] Fix logging of string16s from gfx namespace on Windows. I don't why this fixes it, but somehow having a SelectionModel << logging operator in the gfx namespace makes Visual Studio fail to find the << logging operator for string16 arguments. Per discussion with Scott, we decided to remove the << operators altogether and replace them with a ToString() function to be consistent with Rect, Size, etc. TEST=Check that adding a "LOG(INFO) << text();" line to RenderTextWin compiles. Review URL: https://chromiumcodereview.appspot.com/10332205 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137732 0039d316-1c4b-4281-b951-d872f2087c98 --- ui/base/range/range.cc | 9 +++++---- ui/base/range/range.h | 8 ++++---- ui/gfx/render_text.cc | 11 +++++++---- ui/gfx/selection_model.cc | 17 +++++++++-------- ui/gfx/selection_model.h | 7 +++---- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/ui/base/range/range.cc b/ui/base/range/range.cc index 53223d275420b3..b426a5672b463d 100644 --- a/ui/base/range/range.cc +++ b/ui/base/range/range.cc @@ -1,13 +1,14 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/base/range/range.h" #include -#include +#include "base/format_macros.h" #include "base/logging.h" +#include "base/stringprintf.h" namespace ui { @@ -75,8 +76,8 @@ Range Range::Intersect(const Range& range) const { return Range(min, max); } -std::ostream& operator<<(std::ostream& out, const ui::Range& range) { - return out << "{" << range.start() << "," << range.end() << "}"; +std::string Range::ToString() const { + return base::StringPrintf("{%" PRIuS ",%" PRIuS "}", start(), end()); } } // namespace gfx diff --git a/ui/base/range/range.h b/ui/base/range/range.h index a86233da909e3a..018a11c0b2bcd5 100644 --- a/ui/base/range/range.h +++ b/ui/base/range/range.h @@ -6,7 +6,7 @@ #define UI_BASE_RANGE_RANGE_H_ #pragma once -#include +#include #include "base/basictypes.h" #include "ui/base/ui_export.h" @@ -103,13 +103,13 @@ class UI_EXPORT Range { #endif // GTK+ has no concept of a range. + std::string ToString() const; + private: size_t start_; size_t end_; }; -UI_EXPORT std::ostream& operator<<(std::ostream& out, const ui::Range& range); - -} // namespace gfx +} // namespace ui #endif // UI_BASE_RANGE_RANGE_H_ diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc index 46b1d0031826f6..d7de8a3cd96458 100644 --- a/ui/gfx/render_text.cc +++ b/ui/gfx/render_text.cc @@ -47,11 +47,14 @@ void CheckStyleRanges(const gfx::StyleRanges& style_ranges, size_t length) { for (gfx::StyleRanges::size_type i = 0; i < style_ranges.size() - 1; i++) { const ui::Range& former = style_ranges[i].range; const ui::Range& latter = style_ranges[i + 1].range; - DCHECK(!former.is_empty()) << "Empty range at " << i << ":" << former; - DCHECK(former.IsValid()) << "Invalid range at " << i << ":" << former; - DCHECK(!former.is_reversed()) << "Reversed range at " << i << ":" << former; + DCHECK(!former.is_empty()) << "Empty range at " << i << ":" << + former.ToString(); + DCHECK(former.IsValid()) << "Invalid range at " << i << ":" << + former.ToString(); + DCHECK(!former.is_reversed()) << "Reversed range at " << i << ":" << + former.ToString(); DCHECK(former.end() == latter.start()) << "Ranges gap/overlap/unsorted." << - "former:" << former << ", latter:" << latter; + "former:" << former.ToString() << ", latter:" << latter.ToString(); } const gfx::StyleRange& end_style = *style_ranges.rbegin(); DCHECK(!end_style.range.is_empty()) << "Empty range at end."; diff --git a/ui/gfx/selection_model.cc b/ui/gfx/selection_model.cc index 93aab1bf2167f8..39d4e5a0ffbbca 100644 --- a/ui/gfx/selection_model.cc +++ b/ui/gfx/selection_model.cc @@ -4,7 +4,8 @@ #include "ui/gfx/selection_model.h" -#include +#include "base/format_macros.h" +#include "base/stringprintf.h" namespace gfx { @@ -23,14 +24,14 @@ bool SelectionModel::operator==(const SelectionModel& sel) const { caret_affinity_ == sel.caret_affinity(); } -std::ostream& operator<<(std::ostream& out, const SelectionModel& sel) { - out << '{'; - if (sel.selection().is_empty()) - out << sel.caret_pos(); +std::string SelectionModel::ToString() const { + std::string str = "{"; + if (selection().is_empty()) + base::StringAppendF(&str, "%" PRIuS, caret_pos()); else - out << sel.selection(); - bool backward = sel.caret_affinity() == CURSOR_BACKWARD; - return out << (backward ? ",BACKWARD}" : ",FORWARD}"); + str += selection().ToString(); + const bool backward = caret_affinity() == CURSOR_BACKWARD; + return str + (backward ? ",BACKWARD}" : ",FORWARD}"); } } // namespace gfx diff --git a/ui/gfx/selection_model.h b/ui/gfx/selection_model.h index 44d40031a0df49..c68d6bef7503fe 100644 --- a/ui/gfx/selection_model.h +++ b/ui/gfx/selection_model.h @@ -6,7 +6,7 @@ #define UI_GFX_SELECTION_MODEL_H_ #pragma once -#include +#include #include "ui/base/range/range.h" #include "ui/base/ui_export.h" @@ -77,6 +77,8 @@ class UI_EXPORT SelectionModel { bool operator==(const SelectionModel& sel) const; bool operator!=(const SelectionModel& sel) { return !(*this == sel); } + std::string ToString() const; + private: friend class RenderText; @@ -107,9 +109,6 @@ class UI_EXPORT SelectionModel { LogicalCursorDirection caret_affinity_; }; -UI_EXPORT std::ostream& operator<<(std::ostream& out, - const SelectionModel& sel); - } // namespace gfx #endif // UI_GFX_SELECTION_MODEL_H_