diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/app_list/page_switcher.cc | 3 | ||||
-rw-r--r-- | ui/app_list/search_result_view.cc | 3 | ||||
-rw-r--r-- | ui/gfx/blit.cc | 4 | ||||
-rw-r--r-- | ui/gfx/image/image_skia_operations.cc | 12 | ||||
-rw-r--r-- | ui/gfx/rect.cc | 18 | ||||
-rw-r--r-- | ui/gfx/rect.h | 4 | ||||
-rw-r--r-- | ui/gfx/rect_f.cc | 24 | ||||
-rw-r--r-- | ui/gfx/rect_f.h | 9 | ||||
-rw-r--r-- | ui/gfx/rect_unittest.cc | 12 | ||||
-rw-r--r-- | ui/gfx/screen_gtk.cc | 3 | ||||
-rw-r--r-- | ui/gfx/screen_mac.mm | 3 | ||||
-rw-r--r-- | ui/views/animation/bounds_animator.cc | 3 | ||||
-rw-r--r-- | ui/views/animation/bounds_animator_unittest.cc | 4 | ||||
-rw-r--r-- | ui/views/widget/root_view.cc | 3 |
14 files changed, 74 insertions, 31 deletions
diff --git a/ui/app_list/page_switcher.cc b/ui/app_list/page_switcher.cc index ba98671..1517d39 100644 --- a/ui/app_list/page_switcher.cc +++ b/ui/app_list/page_switcher.cc @@ -189,8 +189,7 @@ void PageSwitcher::Layout() { rect.y(), buttons_size.width(), rect.height()); - rect.Intersect(buttons_bounds); - buttons_->SetBoundsRect(rect); + buttons_->SetBoundsRect(gfx::IntersectRects(rect, buttons_bounds)); } void PageSwitcher::CalculateButtonWidthAndSpacing(int contents_width) { diff --git a/ui/app_list/search_result_view.cc b/ui/app_list/search_result_view.cc index 7e4559d..eb6547d 100644 --- a/ui/app_list/search_result_view.cc +++ b/ui/app_list/search_result_view.cc @@ -200,8 +200,7 @@ void SearchResultView::OnPaint(gfx::Canvas* canvas) { canvas->FillRect(content_rect, kHoverAndPushedColor); } - gfx::Rect border_bottom(rect); - border_bottom.Subtract(content_rect); + gfx::Rect border_bottom = gfx::SubtractRects(rect, content_rect); canvas->FillRect(border_bottom, selected ? kSelectedBorderColor : kBorderColor); diff --git a/ui/gfx/blit.cc b/ui/gfx/blit.cc index 0c6e6b6..41da3f5 100644 --- a/ui/gfx/blit.cc +++ b/ui/gfx/blit.cc @@ -152,8 +152,8 @@ void ScrollCanvas(SkCanvas* canvas, SkAutoLockPixels lock(bitmap); // We expect all coords to be inside the canvas, so clip here. - gfx::Rect clip = in_clip; - clip.Intersect(gfx::Rect(0, 0, bitmap.width(), bitmap.height())); + gfx::Rect clip = gfx::IntersectRects( + in_clip, gfx::Rect(0, 0, bitmap.width(), bitmap.height())); // Compute the set of pixels we'll actually end up painting. gfx::Rect dest_rect = clip; diff --git a/ui/gfx/image/image_skia_operations.cc b/ui/gfx/image/image_skia_operations.cc index 029304b..a2395da 100644 --- a/ui/gfx/image/image_skia_operations.cc +++ b/ui/gfx/image/image_skia_operations.cc @@ -288,11 +288,9 @@ class ExtractSubsetImageSource: public gfx::ImageSkiaSource { // gfx::ImageSkiaSource overrides: virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); - gfx::RectF scaled_subset_bounds = subset_bounds_; - scaled_subset_bounds.Scale( - ui::GetScaleFactorScale(image_rep.scale_factor())); - SkIRect subset_bounds_in_pixel = RectToSkIRect( - ToFlooredRectDeprecated(scaled_subset_bounds)); + float scale_to_pixel = ui::GetScaleFactorScale(image_rep.scale_factor()); + SkIRect subset_bounds_in_pixel = RectToSkIRect(ToFlooredRectDeprecated( + gfx::ScaleRect(subset_bounds_, scale_to_pixel))); SkBitmap dst; bool success = image_rep.sk_bitmap().extractSubset(&dst, subset_bounds_in_pixel); @@ -432,8 +430,8 @@ ImageSkia ImageSkiaOperations::CreateButtonBackground(SkColor color, // static ImageSkia ImageSkiaOperations::ExtractSubset(const ImageSkia& image, const Rect& subset_bounds) { - gfx::Rect clipped_bounds = subset_bounds; - clipped_bounds.Intersect(gfx::Rect(image.size())); + gfx::Rect clipped_bounds = + gfx::IntersectRects(subset_bounds, gfx::Rect(image.size())); if (image.isNull() || clipped_bounds.IsEmpty()) { return ImageSkia(); } diff --git a/ui/gfx/rect.cc b/ui/gfx/rect.cc index b46a9d7..551e6f6 100644 --- a/ui/gfx/rect.cc +++ b/ui/gfx/rect.cc @@ -88,4 +88,22 @@ std::string Rect::ToString() const { size().ToString().c_str()); } +Rect IntersectRects(const Rect& a, const Rect& b) { + Rect result = a; + result.Intersect(b); + return result; +} + +Rect UnionRects(const Rect& a, const Rect& b) { + Rect result = a; + result.Union(b); + return result; +} + +Rect SubtractRects(const Rect& a, const Rect& b) { + Rect result = a; + result.Subtract(b); + return result; +} + } // namespace gfx diff --git a/ui/gfx/rect.h b/ui/gfx/rect.h index 2eab239..bf56896 100644 --- a/ui/gfx/rect.h +++ b/ui/gfx/rect.h @@ -75,6 +75,10 @@ inline bool operator!=(const Rect& lhs, const Rect& rhs) { return !(lhs == rhs); } +UI_EXPORT Rect IntersectRects(const Rect& a, const Rect& b); +UI_EXPORT Rect UnionRects(const Rect& a, const Rect& b); +UI_EXPORT Rect SubtractRects(const Rect& a, const Rect& b); + #if !defined(COMPILER_MSVC) extern template class RectBase<Rect, Point, Size, Insets, int>; #endif diff --git a/ui/gfx/rect_f.cc b/ui/gfx/rect_f.cc index 8503924..6035391 100644 --- a/ui/gfx/rect_f.cc +++ b/ui/gfx/rect_f.cc @@ -42,4 +42,28 @@ std::string RectF::ToString() const { size().ToString().c_str()); } +RectF IntersectRects(const RectF& a, const RectF& b) { + RectF result = a; + result.Intersect(b); + return result; +} + +RectF UnionRects(const RectF& a, const RectF& b) { + RectF result = a; + result.Union(b); + return result; +} + +RectF SubtractRects(const RectF& a, const RectF& b) { + RectF result = a; + result.Subtract(b); + return result; +} + +RectF ScaleRect(const RectF& r, float x_scale, float y_scale) { + RectF result = r; + result.Scale(x_scale, y_scale); + return result; +} + } // namespace gfx diff --git a/ui/gfx/rect_f.h b/ui/gfx/rect_f.h index 4ee1098..8439eb1 100644 --- a/ui/gfx/rect_f.h +++ b/ui/gfx/rect_f.h @@ -49,6 +49,15 @@ inline bool operator!=(const RectF& lhs, const RectF& rhs) { return !(lhs == rhs); } +UI_EXPORT RectF IntersectRects(const RectF& a, const RectF& b); +UI_EXPORT RectF UnionRects(const RectF& a, const RectF& b); +UI_EXPORT RectF SubtractRects(const RectF& a, const RectF& b); +UI_EXPORT RectF ScaleRect(const RectF& r, float x_scale, float y_scale); + +inline RectF ScaleRect(const RectF& r, float scale) { + return ScaleRect(r, scale, scale); +} + #if !defined(COMPILER_MSVC) extern template class RectBase<RectF, PointF, SizeF, InsetsF, float>; #endif diff --git a/ui/gfx/rect_unittest.cc b/ui/gfx/rect_unittest.cc index 6bdbb3b..b83d8a4 100644 --- a/ui/gfx/rect_unittest.cc +++ b/ui/gfx/rect_unittest.cc @@ -107,8 +107,7 @@ TEST(RectTest, Intersect) { gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); gfx::Rect r3(tests[i].x3, tests[i].y3, tests[i].w3, tests[i].h3); - gfx::Rect ir = r1; - ir.Intersect(r2); + gfx::Rect ir = gfx::IntersectRects(r1, r2); EXPECT_EQ(r3.x(), ir.x()); EXPECT_EQ(r3.y(), ir.y()); EXPECT_EQ(r3.width(), ir.width()); @@ -157,8 +156,7 @@ TEST(RectTest, Union) { gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); gfx::Rect r3(tests[i].x3, tests[i].y3, tests[i].w3, tests[i].h3); - gfx::Rect u = r1; - u.Union(r2); + gfx::Rect u = gfx::UnionRects(r1, r2); EXPECT_EQ(r3.x(), u.x()); EXPECT_EQ(r3.y(), u.y()); EXPECT_EQ(r3.width(), u.width()); @@ -446,8 +444,7 @@ TEST(RectTest, ScaleRect) { gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); gfx::RectF r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); - gfx::RectF scaled = r1; - scaled.Scale(tests[i].scale); + gfx::RectF scaled = gfx::ScaleRect(r1, tests[i].scale); EXPECT_FLOAT_AND_NAN_EQ(r2.x(), scaled.x()); EXPECT_FLOAT_AND_NAN_EQ(r2.y(), scaled.y()); EXPECT_FLOAT_AND_NAN_EQ(r2.width(), scaled.width()); @@ -602,8 +599,7 @@ TEST(RectTest, ToRectF) { gfx::Rect a(10, 20, 30, 40); gfx::RectF b(10, 20, 30, 40); - gfx::RectF intersect = b; - intersect.Intersect(a); + gfx::RectF intersect = gfx::IntersectRects(a, b); EXPECT_EQ(b.ToString(), intersect.ToString()); EXPECT_EQ(a, b); diff --git a/ui/gfx/screen_gtk.cc b/ui/gfx/screen_gtk.cc index f3c3b1b..5aefb15 100644 --- a/ui/gfx/screen_gtk.cc +++ b/ui/gfx/screen_gtk.cc @@ -157,8 +157,7 @@ class ScreenGtk : public gfx::Screen { gfx::Display display(0, bounds); gfx::Rect rect; if (GetScreenWorkArea(&rect)) { - bounds.Intersect(rect); - display.set_work_area(bounds); + display.set_work_area(gfx::IntersectRects(rect, bounds)); } else { // Return the best we've got. display.set_work_area(bounds); diff --git a/ui/gfx/screen_mac.mm b/ui/gfx/screen_mac.mm index d3301f1..595ca3e 100644 --- a/ui/gfx/screen_mac.mm +++ b/ui/gfx/screen_mac.mm @@ -39,8 +39,7 @@ NSScreen* GetMatchingScreen(const gfx::Rect& match_rect) { for (NSScreen* screen in [NSScreen screens]) { gfx::Rect monitor_area = ConvertCoordinateSystem([screen frame]); - gfx::Rect intersection = monitor_area; - intersection.Intersect(match_rect); + gfx::Rect intersection = gfx::IntersectRects(monitor_area, match_rect); int area = intersection.width() * intersection.height(); if (area > max_area) { max_area = area; diff --git a/ui/views/animation/bounds_animator.cc b/ui/views/animation/bounds_animator.cc index 037b9d6..c064cc8 100644 --- a/ui/views/animation/bounds_animator.cc +++ b/ui/views/animation/bounds_animator.cc @@ -235,8 +235,7 @@ void BoundsAnimator::AnimationProgressed(const Animation* animation) { gfx::Rect new_bounds = animation->CurrentValueBetween(data.start_bounds, data.target_bounds); if (new_bounds != view->bounds()) { - gfx::Rect total_bounds = view->bounds(); - total_bounds.Union(new_bounds); + gfx::Rect total_bounds = gfx::UnionRects(new_bounds, view->bounds()); // Build up the region to repaint in repaint_bounds_. We'll do the repaint // when all animations complete (in AnimationContainerProgressed). diff --git a/ui/views/animation/bounds_animator_unittest.cc b/ui/views/animation/bounds_animator_unittest.cc index 2dbfc48..c9431f8 100644 --- a/ui/views/animation/bounds_animator_unittest.cc +++ b/ui/views/animation/bounds_animator_unittest.cc @@ -129,8 +129,8 @@ TEST_F(BoundsAnimatorTest, AnimateViewTo) { // The parent should have been told to repaint as the animation progressed. // The resulting rect is the union of the original and target bounds. - target_bounds.Union(initial_bounds); - EXPECT_EQ(target_bounds, parent()->dirty_rect()); + EXPECT_EQ(gfx::UnionRects(target_bounds, initial_bounds), + parent()->dirty_rect()); } // Make sure an AnimationDelegate is deleted when canceled. diff --git a/ui/views/widget/root_view.cc b/ui/views/widget/root_view.cc index ec6dc50..706409c 100644 --- a/ui/views/widget/root_view.cc +++ b/ui/views/widget/root_view.cc @@ -191,8 +191,7 @@ void RootView::SchedulePaintInRect(const gfx::Rect& rect) { layer()->SchedulePaint(rect); } else { gfx::Rect xrect = ConvertRectToParent(rect); - gfx::Rect invalid_rect = GetLocalBounds(); - invalid_rect.Intersect(xrect); + gfx::Rect invalid_rect = gfx::IntersectRects(GetLocalBounds(), xrect); if (!invalid_rect.IsEmpty()) widget_->SchedulePaintInRect(invalid_rect); } |