Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: ui/gfx/render_text.cc

Issue 11293194: ui: Prefer +/- operators to apply offsets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« ui/gfx/rect_unittest.cc ('K') | « ui/gfx/rect_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/break_iterator.h" 9 #include "base/i18n/break_iterator.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 // width increases. 995 // width increases.
996 const int negate_rtl = horizontal_alignment_ == ALIGN_RIGHT ? -1 : 1; 996 const int negate_rtl = horizontal_alignment_ == ALIGN_RIGHT ? -1 : 1;
997 const int offset = negate_rtl * display_offset_.x(); 997 const int offset = negate_rtl * display_offset_.x();
998 if (display_width > (content_width + offset)) { 998 if (display_width > (content_width + offset)) {
999 delta_x = negate_rtl * (display_width - (content_width + offset)); 999 delta_x = negate_rtl * (display_width - (content_width + offset));
1000 } 1000 }
1001 } 1001 }
1002 1002
1003 gfx::Vector2d delta_offset(delta_x, 0); 1003 gfx::Vector2d delta_offset(delta_x, 0);
1004 display_offset_ += delta_offset; 1004 display_offset_ += delta_offset;
1005 cursor_bounds_.Offset(delta_offset); 1005 cursor_bounds_ += delta_offset;
1006 } 1006 }
1007 1007
1008 void RenderText::DrawSelection(Canvas* canvas) { 1008 void RenderText::DrawSelection(Canvas* canvas) {
1009 const SkColor color = focused() ? selection_background_focused_color_ : 1009 const SkColor color = focused() ? selection_background_focused_color_ :
1010 selection_background_unfocused_color_; 1010 selection_background_unfocused_color_;
1011 const std::vector<Rect> sel = GetSubstringBounds(selection()); 1011 const std::vector<Rect> sel = GetSubstringBounds(selection());
1012 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) 1012 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i)
1013 canvas->FillRect(*i, color); 1013 canvas->FillRect(*i, color);
1014 } 1014 }
1015 1015
1016 void RenderText::DrawCursor(Canvas* canvas) { 1016 void RenderText::DrawCursor(Canvas* canvas) {
1017 // Paint cursor. Replace cursor is drawn as rectangle for now. 1017 // Paint cursor. Replace cursor is drawn as rectangle for now.
1018 // TODO(msw): Draw a better cursor with a better indication of association. 1018 // TODO(msw): Draw a better cursor with a better indication of association.
1019 if (cursor_enabled() && cursor_visible() && focused()) { 1019 if (cursor_enabled() && cursor_visible() && focused()) {
1020 const Rect& bounds = GetUpdatedCursorBounds(); 1020 const Rect& bounds = GetUpdatedCursorBounds();
1021 if (bounds.width() != 0) 1021 if (bounds.width() != 0)
1022 canvas->FillRect(bounds, cursor_color_); 1022 canvas->FillRect(bounds, cursor_color_);
1023 else 1023 else
1024 canvas->DrawRect(bounds, cursor_color_); 1024 canvas->DrawRect(bounds, cursor_color_);
1025 } 1025 }
1026 } 1026 }
1027 1027
1028 } // namespace gfx 1028 } // namespace gfx
OLDNEW
« ui/gfx/rect_unittest.cc ('K') | « ui/gfx/rect_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698