Skip to content

Commit

Permalink
Fix logging of string16s from gfx namespace on Windows.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
asvitkine@chromium.org committed May 17, 2012
1 parent d94b1c8 commit 9a55b8c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
9 changes: 5 additions & 4 deletions ui/base/range/range.cc
Original file line number Diff line number Diff line change
@@ -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 <limits>
#include <ostream>

#include "base/format_macros.h"
#include "base/logging.h"
#include "base/stringprintf.h"

namespace ui {

Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions ui/base/range/range.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define UI_BASE_RANGE_RANGE_H_
#pragma once

#include <iosfwd>
#include <string>

#include "base/basictypes.h"
#include "ui/base/ui_export.h"
Expand Down Expand Up @@ -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_
11 changes: 7 additions & 4 deletions ui/gfx/render_text.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down
17 changes: 9 additions & 8 deletions ui/gfx/selection_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

#include "ui/gfx/selection_model.h"

#include <ostream>
#include "base/format_macros.h"
#include "base/stringprintf.h"

namespace gfx {

Expand All @@ -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
7 changes: 3 additions & 4 deletions ui/gfx/selection_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define UI_GFX_SELECTION_MODEL_H_
#pragma once

#include <iosfwd>
#include <string>

#include "ui/base/range/range.h"
#include "ui/base/ui_export.h"
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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_

0 comments on commit 9a55b8c

Please sign in to comment.