1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_BASE_COCOA_THREE_PART_IMAGE_H
6 #define UI_BASE_COCOA_THREE_PART_IMAGE_H
8 #import <Cocoa/Cocoa.h>
10 #include "base/mac/scoped_nsobject.h"
11 #include "ui/base/ui_base_export.h"
15 // A wrapper around NSDrawThreePartImage that caches the images.
16 // The middle image is optional.
17 // Vertical orientation is not currently supported.
18 class UI_BASE_EXPORT ThreePartImage
{
20 // |left_id|, |middle_id|, and |right_id| are ResourceBundle image
21 // identifiers. Specify 0 for |middle_id| if there is no middle image.
22 ThreePartImage(int left_id
, int middle_id
, int right_id
);
25 // Returns the image rects if drawn in |bounds|.
26 NSRect
GetLeftRect(NSRect bounds
) const;
27 NSRect
GetMiddleRect(NSRect bounds
) const;
28 NSRect
GetRightRect(NSRect bounds
) const;
30 // Draws the three part image inside |rect|.
31 void DrawInRect(NSRect rect
, NSCompositingOperation op
, CGFloat alpha
) const;
33 // Returns YES if |point| is in a non-transparent part of the images.
34 // Returns YES if |point| is inside the middle rect and there is no middle
36 BOOL
HitTest(NSPoint point
, NSRect bounds
) const;
39 // Returns YES if |point| is in a non-transparent part of |image|.
40 BOOL
HitTestImage(NSPoint point
, NSImage
* image
, NSRect imageRect
) const;
42 base::scoped_nsobject
<NSImage
> leftImage_
;
43 base::scoped_nsobject
<NSImage
> middleImage_
;
44 base::scoped_nsobject
<NSImage
> rightImage_
;
48 DISALLOW_COPY_AND_ASSIGN(ThreePartImage
);
53 #endif // UI_BASE_COCOA_THREE_PART_IMAGE_H