diff options
author | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-23 16:51:47 +0000 |
---|---|---|
committer | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-23 16:51:47 +0000 |
commit | d40305001bfd61bef7e118c8580895f68d36b163 (patch) | |
tree | 05a4a731233c5cb3deb56306019231e22d474deb /content/browser/renderer_host/render_widget_host_view_gtk.cc | |
parent | ea75f30985b5b24627bed4c613a1ef403235aa02 (diff) | |
download | chromium_src-d40305001bfd61bef7e118c8580895f68d36b163.zip chromium_src-d40305001bfd61bef7e118c8580895f68d36b163.tar.gz chromium_src-d40305001bfd61bef7e118c8580895f68d36b163.tar.bz2 |
Make gfx::Rect class operations consistently mutate the class they are called on.
Currently some methods mutate the class, and some return a new value, requiring
API users to know what kind of method they are calling each time, and making
inconsistent code. For example:
gfx::Rect rect;
rect.Inset(1, 1, 1, 1);
rect = rect.Intersect(other_rect);
rect.Offset(1, 1);
Instead of:
gfx::Rect rect;
rect.Inset(1, 1, 1, 1);
rect.Intersect(other_rect);
rect.Offset(1, 1);
We could go either way - making the class immutable or all methods return a new
instance - but I believe it is better to instead make all methods mutate the
class. This allows for shorter lines of code by avoiding having to repeat the
object's name twice in order to change it.
This patch changes gfx::Rect classes and all the callsites that uses these
methods. It should make no change in behaviour, so no new tests added.
R=sky
BUG=147395
Review URL: https://codereview.chromium.org/11110004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163579 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/renderer_host/render_widget_host_view_gtk.cc')
-rw-r--r-- | content/browser/renderer_host/render_widget_host_view_gtk.cc | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/content/browser/renderer_host/render_widget_host_view_gtk.cc b/content/browser/renderer_host/render_widget_host_view_gtk.cc index c68dfb1..dbe534d4 100644 --- a/content/browser/renderer_host/render_widget_host_view_gtk.cc +++ b/content/browser/renderer_host/render_widget_host_view_gtk.cc @@ -858,19 +858,20 @@ void RenderWidgetHostViewGtk::DidUpdateBackingStore( // be done using XCopyArea? Perhaps similar to // BackingStore::ScrollBackingStore? if (about_to_validate_and_paint_) - invalid_rect_ = invalid_rect_.Union(scroll_rect); + invalid_rect_.Union(scroll_rect); else Paint(scroll_rect); for (size_t i = 0; i < copy_rects.size(); ++i) { // Avoid double painting. NOTE: This is only relevant given the call to // Paint(scroll_rect) above. - gfx::Rect rect = copy_rects[i].Subtract(scroll_rect); + gfx::Rect rect = copy_rects[i]; + rect.Subtract(scroll_rect); if (rect.IsEmpty()) continue; if (about_to_validate_and_paint_) - invalid_rect_ = invalid_rect_.Union(rect); + invalid_rect_.Union(rect); else Paint(rect); } @@ -968,7 +969,9 @@ void RenderWidgetHostViewGtk::SelectionBoundsChanged( WebKit::WebTextDirection start_direction, const gfx::Rect& end_rect, WebKit::WebTextDirection end_direction) { - im_context_->UpdateCaretBounds(start_rect.Union(end_rect)); + gfx::Rect combined_rect = start_rect; + combined_rect.Union(end_rect); + im_context_->UpdateCaretBounds(combined_rect); } GdkEventButton* RenderWidgetHostViewGtk::GetLastMouseDown() { @@ -1175,7 +1178,7 @@ void RenderWidgetHostViewGtk::Paint(const gfx::Rect& damage_rect) { about_to_validate_and_paint_ = false; gfx::Rect paint_rect = gfx::Rect(0, 0, kMaxWindowWidth, kMaxWindowHeight); - paint_rect = paint_rect.Intersect(invalid_rect_); + paint_rect.Intersect(invalid_rect_); if (backing_store) { // Only render the widget if it is attached to a window; there's a short |