Skip to content

Commit

Permalink
Remove explicit namespace resolution from code in gfx namespace
Browse files Browse the repository at this point in the history
BUG=103304
R=sky@chromium.org

Review URL: https://codereview.chromium.org/24053002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223952 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
ckocagil@chromium.org committed Sep 18, 2013
1 parent 7222181 commit 3dfe5c5
Show file tree
Hide file tree
Showing 14 changed files with 171 additions and 175 deletions.
12 changes: 6 additions & 6 deletions ui/gfx/break_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BreakList {
void SetValue(T value);

// Adjust the breaks to apply |value| over the supplied |range|.
void ApplyValue(T value, const gfx::Range& range);
void ApplyValue(T value, const Range& range);

// Set the max position and trim any breaks at or beyond that position.
void SetMax(size_t max);
Expand All @@ -52,7 +52,7 @@ class BreakList {

// Get the range of the supplied break; returns the break's start position and
// the next break's start position (or |max_| for the terminal break).
gfx::Range GetRange(const typename BreakList<T>::const_iterator& i) const;
Range GetRange(const typename BreakList<T>::const_iterator& i) const;

// Comparison functions for testing purposes.
bool EqualsValueForTesting(T value) const;
Expand Down Expand Up @@ -83,12 +83,12 @@ void BreakList<T>::SetValue(T value) {
}

template<class T>
void BreakList<T>::ApplyValue(T value, const gfx::Range& range) {
void BreakList<T>::ApplyValue(T value, const Range& range) {
if (!range.IsValid() || range.is_empty())
return;
DCHECK(!breaks_.empty());
DCHECK(!range.is_reversed());
DCHECK(gfx::Range(0, max_).Contains(range));
DCHECK(Range(0, max_).Contains(range));

// Erase any breaks in |range|, then add start and end breaks as needed.
typename std::vector<Break>::iterator start = GetBreak(range.start());
Expand Down Expand Up @@ -136,10 +136,10 @@ typename std::vector<std::pair<size_t, T> >::const_iterator
}

template<class T>
gfx::Range BreakList<T>::GetRange(
Range BreakList<T>::GetRange(
const typename BreakList<T>::const_iterator& i) const {
const typename BreakList<T>::const_iterator next = i + 1;
return gfx::Range(i->first, next == breaks_.end() ? max_ : next->first);
return Range(i->first, next == breaks_.end() ? max_ : next->first);
}

template<class T>
Expand Down
80 changes: 40 additions & 40 deletions ui/gfx/break_list_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ TEST_F(BreakListTest, ApplyValue) {
breaks.SetMax(max);

// Ensure ApplyValue is a no-op on invalid and empty ranges.
breaks.ApplyValue(true, gfx::Range::InvalidRange());
breaks.ApplyValue(true, Range::InvalidRange());
EXPECT_TRUE(breaks.EqualsValueForTesting(false));
for (size_t i = 0; i < 3; ++i) {
breaks.ApplyValue(true, gfx::Range(i, i));
breaks.ApplyValue(true, Range(i, i));
EXPECT_TRUE(breaks.EqualsValueForTesting(false));
}

Expand All @@ -45,7 +45,7 @@ TEST_F(BreakListTest, ApplyValue) {
expected.push_back(std::pair<size_t, bool>(2, true));
expected.push_back(std::pair<size_t, bool>(3, false));
for (size_t i = 0; i < 2; ++i) {
breaks.ApplyValue(true, gfx::Range(2, 3));
breaks.ApplyValue(true, Range(2, 3));
EXPECT_TRUE(breaks.EqualsForTesting(expected));
}

Expand All @@ -54,43 +54,43 @@ TEST_F(BreakListTest, ApplyValue) {
EXPECT_TRUE(breaks.EqualsValueForTesting(true));

// Ensure applying a value over [0, |max|) is the same as setting a value.
breaks.ApplyValue(false, gfx::Range(0, max));
breaks.ApplyValue(false, Range(0, max));
EXPECT_TRUE(breaks.EqualsValueForTesting(false));

// Ensure applying a value that is already applied has no effect.
breaks.ApplyValue(false, gfx::Range(0, 2));
breaks.ApplyValue(false, gfx::Range(3, 6));
breaks.ApplyValue(false, gfx::Range(7, max));
breaks.ApplyValue(false, Range(0, 2));
breaks.ApplyValue(false, Range(3, 6));
breaks.ApplyValue(false, Range(7, max));
EXPECT_TRUE(breaks.EqualsValueForTesting(false));

// Ensure applying an identical neighboring value merges the ranges.
breaks.ApplyValue(true, gfx::Range(0, 3));
breaks.ApplyValue(true, gfx::Range(3, 6));
breaks.ApplyValue(true, gfx::Range(6, max));
breaks.ApplyValue(true, Range(0, 3));
breaks.ApplyValue(true, Range(3, 6));
breaks.ApplyValue(true, Range(6, max));
EXPECT_TRUE(breaks.EqualsValueForTesting(true));

// Ensure applying a value with the same range overrides the ranged value.
breaks.ApplyValue(false, gfx::Range(2, 3));
breaks.ApplyValue(true, gfx::Range(2, 3));
breaks.ApplyValue(false, Range(2, 3));
breaks.ApplyValue(true, Range(2, 3));
EXPECT_TRUE(breaks.EqualsValueForTesting(true));

// Ensure applying a value with a containing range overrides contained values.
breaks.ApplyValue(false, gfx::Range(0, 1));
breaks.ApplyValue(false, gfx::Range(2, 3));
breaks.ApplyValue(true, gfx::Range(0, 3));
breaks.ApplyValue(false, Range(0, 1));
breaks.ApplyValue(false, Range(2, 3));
breaks.ApplyValue(true, Range(0, 3));
EXPECT_TRUE(breaks.EqualsValueForTesting(true));
breaks.ApplyValue(false, gfx::Range(4, 5));
breaks.ApplyValue(false, gfx::Range(6, 7));
breaks.ApplyValue(false, gfx::Range(8, 9));
breaks.ApplyValue(true, gfx::Range(4, 9));
breaks.ApplyValue(false, Range(4, 5));
breaks.ApplyValue(false, Range(6, 7));
breaks.ApplyValue(false, Range(8, 9));
breaks.ApplyValue(true, Range(4, 9));
EXPECT_TRUE(breaks.EqualsValueForTesting(true));

// Ensure applying various overlapping values yields the intended results.
breaks.ApplyValue(false, gfx::Range(1, 4));
breaks.ApplyValue(false, gfx::Range(5, 8));
breaks.ApplyValue(true, gfx::Range(0, 2));
breaks.ApplyValue(true, gfx::Range(3, 6));
breaks.ApplyValue(true, gfx::Range(7, max));
breaks.ApplyValue(false, Range(1, 4));
breaks.ApplyValue(false, Range(5, 8));
breaks.ApplyValue(true, Range(0, 2));
breaks.ApplyValue(true, Range(3, 6));
breaks.ApplyValue(true, Range(7, max));
std::vector<std::pair<size_t, bool> > overlap;
overlap.push_back(std::pair<size_t, bool>(0, true));
overlap.push_back(std::pair<size_t, bool>(2, false));
Expand All @@ -104,9 +104,9 @@ TEST_F(BreakListTest, SetMax) {
// Ensure values adjust to accommodate max position changes.
BreakList<bool> breaks(false);
breaks.SetMax(9);
breaks.ApplyValue(true, gfx::Range(0, 2));
breaks.ApplyValue(true, gfx::Range(3, 6));
breaks.ApplyValue(true, gfx::Range(7, 9));
breaks.ApplyValue(true, Range(0, 2));
breaks.ApplyValue(true, Range(3, 6));
breaks.ApplyValue(true, Range(7, 9));

std::vector<std::pair<size_t, bool> > expected;
expected.push_back(std::pair<size_t, bool>(0, true));
Expand Down Expand Up @@ -134,25 +134,25 @@ TEST_F(BreakListTest, SetMax) {
TEST_F(BreakListTest, GetBreakAndRange) {
BreakList<bool> breaks(false);
breaks.SetMax(8);
breaks.ApplyValue(true, gfx::Range(1, 2));
breaks.ApplyValue(true, gfx::Range(4, 6));
breaks.ApplyValue(true, Range(1, 2));
breaks.ApplyValue(true, Range(4, 6));

struct {
size_t position;
size_t break_index;
gfx::Range range;
Range range;
} cases[] = {
{ 0, 0, gfx::Range(0, 1) },
{ 1, 1, gfx::Range(1, 2) },
{ 2, 2, gfx::Range(2, 4) },
{ 3, 2, gfx::Range(2, 4) },
{ 4, 3, gfx::Range(4, 6) },
{ 5, 3, gfx::Range(4, 6) },
{ 6, 4, gfx::Range(6, 8) },
{ 7, 4, gfx::Range(6, 8) },
{ 0, 0, Range(0, 1) },
{ 1, 1, Range(1, 2) },
{ 2, 2, Range(2, 4) },
{ 3, 2, Range(2, 4) },
{ 4, 3, Range(4, 6) },
{ 5, 3, Range(4, 6) },
{ 6, 4, Range(6, 8) },
{ 7, 4, Range(6, 8) },
// Positions at or beyond the max simply return the last break and range.
{ 8, 4, gfx::Range(6, 8) },
{ 9, 4, gfx::Range(6, 8) },
{ 8, 4, Range(6, 8) },
{ 9, 4, Range(6, 8) },
};


Expand Down
14 changes: 7 additions & 7 deletions ui/gfx/canvas_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,31 @@ bool PixelShouldGetHalo(const SkBitmap& bitmap,
// Strips accelerator character prefixes in |text| if needed, based on |flags|.
// Returns a range in |text| to underline or gfx::Range::InvalidRange() if
// underlining is not needed.
gfx::Range StripAcceleratorChars(int flags, base::string16* text) {
Range StripAcceleratorChars(int flags, base::string16* text) {
if (flags & (Canvas::SHOW_PREFIX | Canvas::HIDE_PREFIX)) {
int char_pos = -1;
int char_span = 0;
*text = RemoveAcceleratorChar(*text, '&', &char_pos, &char_span);
if ((flags & Canvas::SHOW_PREFIX) && char_pos != -1)
return gfx::Range(char_pos, char_pos + char_span);
return Range(char_pos, char_pos + char_span);
}
return gfx::Range::InvalidRange();
return Range::InvalidRange();
}

// Elides |text| and adjusts |range| appropriately. If eliding causes |range|
// to no longer point to the same character in |text|, |range| is made invalid.
void ElideTextAndAdjustRange(const FontList& font_list,
int width,
base::string16* text,
gfx::Range* range) {
Range* range) {
const base::char16 start_char =
(range->IsValid() ? text->at(range->start()) : 0);
*text = gfx::ElideText(*text, font_list, width, gfx::ELIDE_AT_END);
if (!range->IsValid())
return;
if (range->start() >= text->length() ||
text->at(range->start()) != start_char) {
*range = gfx::Range::InvalidRange();
*range = Range::InvalidRange();
}
}

Expand Down Expand Up @@ -272,7 +272,7 @@ void Canvas::DrawStringRectWithShadows(const base::string16& text,
&strings);

for (size_t i = 0; i < strings.size(); i++) {
gfx::Range range = StripAcceleratorChars(flags, &strings[i]);
Range range = StripAcceleratorChars(flags, &strings[i]);
UpdateRenderText(rect, strings[i], font_list, flags, color,
render_text.get());
int line_padding = 0;
Expand All @@ -299,7 +299,7 @@ void Canvas::DrawStringRectWithShadows(const base::string16& text,
rect += Vector2d(0, line_height);
}
} else {
gfx::Range range = StripAcceleratorChars(flags, &adjusted_text);
Range range = StripAcceleratorChars(flags, &adjusted_text);
bool elide_text = ((flags & NO_ELLIPSIS) == 0);

#if defined(OS_LINUX)
Expand Down
43 changes: 20 additions & 23 deletions ui/gfx/render_text.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ StyleIterator::StyleIterator(const BreakList<SkColor>& colors,

StyleIterator::~StyleIterator() {}

gfx::Range StyleIterator::GetRange() const {
gfx::Range range(colors_.GetRange(color_));
Range StyleIterator::GetRange() const {
Range range(colors_.GetRange(color_));
for (size_t i = 0; i < NUM_TEXT_STYLES; ++i)
range = range.Intersect(styles_[i].GetRange(style_[i]));
return range;
Expand Down Expand Up @@ -450,8 +450,8 @@ void RenderText::MoveCursor(BreakType break_type,
bool RenderText::MoveCursorTo(const SelectionModel& model) {
// Enforce valid selection model components.
size_t text_length = text().length();
gfx::Range range(std::min(model.selection().start(), text_length),
std::min(model.caret_pos(), text_length));
Range range(std::min(model.selection().start(), text_length),
std::min(model.caret_pos(), text_length));
// The current model only supports caret positions at valid character indices.
if (!IsCursorablePosition(range.start()) ||
!IsCursorablePosition(range.end()))
Expand All @@ -469,9 +469,9 @@ bool RenderText::MoveCursorTo(const Point& point, bool select) {
return MoveCursorTo(position);
}

bool RenderText::SelectRange(const gfx::Range& range) {
gfx::Range sel(std::min(range.start(), text().length()),
std::min(range.end(), text().length()));
bool RenderText::SelectRange(const Range& range) {
Range sel(std::min(range.start(), text().length()),
std::min(range.end(), text().length()));
if (!IsCursorablePosition(sel.start()) || !IsCursorablePosition(sel.end()))
return false;
LogicalCursorDirection affinity =
Expand All @@ -495,8 +495,7 @@ void RenderText::ClearSelection() {

void RenderText::SelectAll(bool reversed) {
const size_t length = text().length();
const gfx::Range all = reversed ? gfx::Range(length, 0) :
gfx::Range(0, length);
const Range all = reversed ? Range(length, 0) : Range(0, length);
const bool success = SelectRange(all);
DCHECK(success);
}
Expand Down Expand Up @@ -537,13 +536,13 @@ void RenderText::SelectWord() {
MoveCursorTo(reversed ? selection_min : selection_max, true);
}

const gfx::Range& RenderText::GetCompositionRange() const {
const Range& RenderText::GetCompositionRange() const {
return composition_range_;
}

void RenderText::SetCompositionRange(const gfx::Range& composition_range) {
void RenderText::SetCompositionRange(const Range& composition_range) {
CHECK(!composition_range.IsValid() ||
gfx::Range(0, text_.length()).Contains(composition_range));
Range(0, text_.length()).Contains(composition_range));
composition_range_.set_end(composition_range.end());
composition_range_.set_start(composition_range.start());
ResetLayout();
Expand All @@ -559,7 +558,7 @@ void RenderText::SetColor(SkColor value) {
#endif
}

void RenderText::ApplyColor(SkColor value, const gfx::Range& range) {
void RenderText::ApplyColor(SkColor value, const Range& range) {
colors_.ApplyValue(value, range);

#if defined(OS_WIN)
Expand All @@ -584,9 +583,7 @@ void RenderText::SetStyle(TextStyle style, bool value) {
}
}

void RenderText::ApplyStyle(TextStyle style,
bool value,
const gfx::Range& range) {
void RenderText::ApplyStyle(TextStyle style, bool value, const Range& range) {
styles_[style].ApplyValue(value, range);

// Only invalidate the layout on font changes; not for colors or decorations.
Expand Down Expand Up @@ -728,7 +725,7 @@ Rect RenderText::GetCursorBounds(const SelectionModel& caret,
} else {
size_t grapheme_start = (caret_affinity == CURSOR_FORWARD) ?
caret_pos : IndexOfAdjacentGrapheme(caret_pos, CURSOR_BACKWARD);
gfx::Range xspan(GetGlyphBounds(grapheme_start));
Range xspan(GetGlyphBounds(grapheme_start));
if (insert_mode) {
x = (caret_affinity == CURSOR_BACKWARD) ? xspan.end() : xspan.start();
} else { // overtype mode
Expand Down Expand Up @@ -769,7 +766,7 @@ size_t RenderText::IndexOfAdjacentGrapheme(size_t index,
}

SelectionModel RenderText::GetSelectionModelForSelectionStart() {
const gfx::Range& sel = selection();
const Range& sel = selection();
if (sel.is_empty())
return selection_model_;
return SelectionModel(sel.start(),
Expand All @@ -792,7 +789,7 @@ RenderText::RenderText()
selection_color_(kDefaultColor),
selection_background_focused_color_(kDefaultSelectionBackgroundColor),
focused_(false),
composition_range_(gfx::Range::InvalidRange()),
composition_range_(Range::InvalidRange()),
colors_(kDefaultColor),
styles_(NUM_TEXT_STYLES),
composition_and_selection_styles_applied_(false),
Expand Down Expand Up @@ -875,7 +872,7 @@ void RenderText::ApplyCompositionAndSelectionStyles() {

// Apply the selected text color to the [un-reversed] selection range.
if (!selection().is_empty()) {
const gfx::Range range(selection().GetMin(), selection().GetMax());
const Range range(selection().GetMin(), selection().GetMax());
colors_.ApplyValue(selection_color_, range);
}
composition_and_selection_styles_applied_ = true;
Expand Down Expand Up @@ -1029,20 +1026,20 @@ void RenderText::ApplyTextShadows(internal::SkiaTextRenderer* renderer) {
}

// static
bool RenderText::RangeContainsCaret(const gfx::Range& range,
bool RenderText::RangeContainsCaret(const Range& range,
size_t caret_pos,
LogicalCursorDirection caret_affinity) {
// NB: exploits unsigned wraparound (WG14/N1124 section 6.2.5 paragraph 9).
size_t adjacent = (caret_affinity == CURSOR_BACKWARD) ?
caret_pos - 1 : caret_pos + 1;
return range.Contains(gfx::Range(caret_pos, adjacent));
return range.Contains(Range(caret_pos, adjacent));
}

void RenderText::MoveCursorTo(size_t position, bool select) {
size_t cursor = std::min(position, text().length());
if (IsCursorablePosition(cursor))
SetSelectionModel(SelectionModel(
gfx::Range(select ? selection().start() : cursor, cursor),
Range(select ? selection().start() : cursor, cursor),
(cursor == 0) ? CURSOR_FORWARD : CURSOR_BACKWARD));
}

Expand Down
Loading

0 comments on commit 3dfe5c5

Please sign in to comment.