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

Unified Diff: ui/base/cocoa/three_part_image.mm

Issue 918533005: Mac: Optimize TabView drawing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split ThreePartImage Created 5 years, 10 months 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 side-by-side diff with in-line comments
Download patch
Index: ui/base/cocoa/three_part_image.mm
diff --git a/ui/base/cocoa/three_part_image.mm b/ui/base/cocoa/three_part_image.mm
new file mode 100644
index 0000000000000000000000000000000000000000..5fb8916f9f20ba858d640eebec3b2a55a1d5b5d0
--- /dev/null
+++ b/ui/base/cocoa/three_part_image.mm
@@ -0,0 +1,82 @@
+// Copyright 2015 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/cocoa/three_part_image.h"
+
+#include "base/logging.h"
+#include "ui/base/resource/resource_bundle.h"
+
+namespace ui {
+
+ThreePartImage::ThreePartImage(int left_id, int middle_id, int right_id) {
+ DCHECK(left_id);
+ DCHECK(right_id);
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ leftImage_.reset(rb.GetNativeImageNamed(left_id).CopyNSImage());
+ rightImage_.reset(rb.GetNativeImageNamed(right_id).CopyNSImage());
+ leftSize_ = [leftImage_ size];
+ rightSize_ = [rightImage_ size];
+
+ if (middle_id)
+ middleImage_.reset(rb.GetNativeImageNamed(middle_id).CopyNSImage());
+}
+
+ThreePartImage::~ThreePartImage() {
+}
+
+NSRect ThreePartImage::GetLeftRect(NSRect bounds) const {
+ NSRect left, right;
+ NSDivideRect(bounds, &left, &right, leftSize_.width, NSMinXEdge);
+ return left;
+}
+
+NSRect ThreePartImage::GetMiddleRect(NSRect bounds) const {
+ NSRect left, middle, right;
+ NSDivideRect(bounds, &left, &middle, leftSize_.width, NSMinXEdge);
+ NSDivideRect(middle, &right, &middle, rightSize_.width, NSMaxXEdge);
+ return middle;
+}
+
+NSRect ThreePartImage::GetRightRect(NSRect bounds) const {
+ NSRect left, right;
+ NSDivideRect(bounds, &right, &left, rightSize_.width, NSMaxXEdge);
+ return right;
+}
+
+void ThreePartImage::DrawInRect(NSRect rect,
+ NSCompositingOperation op,
+ CGFloat alpha) const {
+ rect.size.height = leftSize_.height;
+ NSDrawThreePartImage(rect, leftImage_, middleImage_, rightImage_,
+ NO, op, alpha, NO);
+}
+
+BOOL ThreePartImage::HitTest(NSPoint point, NSRect bounds) const {
+ NSRect middleRect = GetMiddleRect(bounds);
+ if (NSPointInRect(point, middleRect))
+ return middleImage_ ? HitTestImage(point, middleImage_, middleRect) : YES;
+
+ NSRect leftRect = GetLeftRect(bounds);
+ if (NSPointInRect(point, leftRect))
+ return HitTestImage(point, leftImage_, leftRect);
+
+ NSRect rightRect = GetRightRect(bounds);
+ if (NSPointInRect(point, rightRect))
+ return HitTestImage(point, rightImage_, rightRect);
+
+ return NO;
+}
+
+BOOL ThreePartImage::HitTestImage(NSPoint point,
+ NSImage* image,
+ NSRect imageRect) const {
+ NSRect pointRect = NSMakeRect(point.x, point.y, 1, 1);
+ return [image hitTestRect:pointRect
+ withImageDestinationRect:imageRect
+ context:nil
+ hints:nil
+ flipped:NO];
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698