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
parent d94b1c82
// 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ui/base/range/range.h" #include "ui/base/range/range.h"
#include <limits> #include <limits>
#include <ostream>
#include "base/format_macros.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/stringprintf.h"
namespace ui { namespace ui {
...@@ -75,8 +76,8 @@ Range Range::Intersect(const Range& range) const { ...@@ -75,8 +76,8 @@ Range Range::Intersect(const Range& range) const {
return Range(min, max); return Range(min, max);
} }
std::ostream& operator<<(std::ostream& out, const ui::Range& range) { std::string Range::ToString() const {
return out << "{" << range.start() << "," << range.end() << "}"; return base::StringPrintf("{%" PRIuS ",%" PRIuS "}", start(), end());
} }
} // namespace gfx } // namespace gfx
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define UI_BASE_RANGE_RANGE_H_ #define UI_BASE_RANGE_RANGE_H_
#pragma once #pragma once
#include <iosfwd> #include <string>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "ui/base/ui_export.h" #include "ui/base/ui_export.h"
...@@ -103,13 +103,13 @@ class UI_EXPORT Range { ...@@ -103,13 +103,13 @@ class UI_EXPORT Range {
#endif #endif
// GTK+ has no concept of a range. // GTK+ has no concept of a range.
std::string ToString() const;
private: private:
size_t start_; size_t start_;
size_t end_; size_t end_;
}; };
UI_EXPORT std::ostream& operator<<(std::ostream& out, const ui::Range& range); } // namespace ui
} // namespace gfx
#endif // UI_BASE_RANGE_RANGE_H_ #endif // UI_BASE_RANGE_RANGE_H_
...@@ -47,11 +47,14 @@ void CheckStyleRanges(const gfx::StyleRanges& style_ranges, size_t length) { ...@@ -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++) { for (gfx::StyleRanges::size_type i = 0; i < style_ranges.size() - 1; i++) {
const ui::Range& former = style_ranges[i].range; const ui::Range& former = style_ranges[i].range;
const ui::Range& latter = style_ranges[i + 1].range; const ui::Range& latter = style_ranges[i + 1].range;
DCHECK(!former.is_empty()) << "Empty range at " << i << ":" << former; DCHECK(!former.is_empty()) << "Empty range at " << i << ":" <<
DCHECK(former.IsValid()) << "Invalid range at " << i << ":" << former; former.ToString();
DCHECK(!former.is_reversed()) << "Reversed range at " << i << ":" << former; 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." << 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(); const gfx::StyleRange& end_style = *style_ranges.rbegin();
DCHECK(!end_style.range.is_empty()) << "Empty range at end."; DCHECK(!end_style.range.is_empty()) << "Empty range at end.";
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
#include "ui/gfx/selection_model.h" #include "ui/gfx/selection_model.h"
#include <ostream> #include "base/format_macros.h"
#include "base/stringprintf.h"
namespace gfx { namespace gfx {
...@@ -23,14 +24,14 @@ bool SelectionModel::operator==(const SelectionModel& sel) const { ...@@ -23,14 +24,14 @@ bool SelectionModel::operator==(const SelectionModel& sel) const {
caret_affinity_ == sel.caret_affinity(); caret_affinity_ == sel.caret_affinity();
} }
std::ostream& operator<<(std::ostream& out, const SelectionModel& sel) { std::string SelectionModel::ToString() const {
out << '{'; std::string str = "{";
if (sel.selection().is_empty()) if (selection().is_empty())
out << sel.caret_pos(); base::StringAppendF(&str, "%" PRIuS, caret_pos());
else else
out << sel.selection(); str += selection().ToString();
bool backward = sel.caret_affinity() == CURSOR_BACKWARD; const bool backward = caret_affinity() == CURSOR_BACKWARD;
return out << (backward ? ",BACKWARD}" : ",FORWARD}"); return str + (backward ? ",BACKWARD}" : ",FORWARD}");
} }
} // namespace gfx } // namespace gfx
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define UI_GFX_SELECTION_MODEL_H_ #define UI_GFX_SELECTION_MODEL_H_
#pragma once #pragma once
#include <iosfwd> #include <string>
#include "ui/base/range/range.h" #include "ui/base/range/range.h"
#include "ui/base/ui_export.h" #include "ui/base/ui_export.h"
...@@ -77,6 +77,8 @@ class UI_EXPORT SelectionModel { ...@@ -77,6 +77,8 @@ class UI_EXPORT SelectionModel {
bool operator==(const SelectionModel& sel) const; bool operator==(const SelectionModel& sel) const;
bool operator!=(const SelectionModel& sel) { return !(*this == sel); } bool operator!=(const SelectionModel& sel) { return !(*this == sel); }
std::string ToString() const;
private: private:
friend class RenderText; friend class RenderText;
...@@ -107,9 +109,6 @@ class UI_EXPORT SelectionModel { ...@@ -107,9 +109,6 @@ class UI_EXPORT SelectionModel {
LogicalCursorDirection caret_affinity_; LogicalCursorDirection caret_affinity_;
}; };
UI_EXPORT std::ostream& operator<<(std::ostream& out,
const SelectionModel& sel);
} // namespace gfx } // namespace gfx
#endif // UI_GFX_SELECTION_MODEL_H_ #endif // UI_GFX_SELECTION_MODEL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment