OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 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. | |
4 | |
5 #import "chrome/browser/ui/cocoa/find_bar_view.h" | |
6 | |
7 #import "chrome/browser/ui/cocoa/themed_window.h" | |
8 #import "chrome/browser/ui/cocoa/url_drop_target.h" | |
9 #import "chrome/browser/ui/cocoa/view_id_util.h" | |
10 | |
11 namespace { | |
12 CGFloat kCurveSize = 8; | |
13 } // end namespace | |
14 | |
15 @implementation FindBarView | |
16 | |
17 - (void)awakeFromNib { | |
18 // Register for all the drag types handled by the RWHVCocoa. | |
19 [self registerForDraggedTypes:[URLDropTargetHandler handledDragTypes]]; | |
20 } | |
21 | |
22 - (void)drawRect:(NSRect)rect { | |
23 // TODO(rohitrao): Make this prettier. | |
24 rect = NSInsetRect([self bounds], 0.5, 0.5); | |
25 rect = NSOffsetRect(rect, 0, 1.0); | |
26 | |
27 NSPoint topLeft = NSMakePoint(NSMinX(rect), NSMaxY(rect)); | |
28 NSPoint topRight = NSMakePoint(NSMaxX(rect), NSMaxY(rect)); | |
29 NSPoint midLeft1 = | |
30 NSMakePoint(NSMinX(rect) + kCurveSize, NSMaxY(rect) - kCurveSize); | |
31 NSPoint midLeft2 = | |
32 NSMakePoint(NSMinX(rect) + kCurveSize, NSMinY(rect) + kCurveSize); | |
33 NSPoint midRight1 = | |
34 NSMakePoint(NSMaxX(rect) - kCurveSize, NSMinY(rect) + kCurveSize); | |
35 NSPoint midRight2 = | |
36 NSMakePoint(NSMaxX(rect) - kCurveSize, NSMaxY(rect) - kCurveSize); | |
37 NSPoint bottomLeft = | |
38 NSMakePoint(NSMinX(rect) + (2 * kCurveSize), NSMinY(rect)); | |
39 NSPoint bottomRight = | |
40 NSMakePoint(NSMaxX(rect) - (2 * kCurveSize), NSMinY(rect)); | |
41 | |
42 NSBezierPath* path = [NSBezierPath bezierPath]; | |
43 [path moveToPoint:topLeft]; | |
44 [path curveToPoint:midLeft1 | |
45 controlPoint1:NSMakePoint(midLeft1.x, topLeft.y) | |
46 controlPoint2:NSMakePoint(midLeft1.x, topLeft.y)]; | |
47 [path lineToPoint:midLeft2]; | |
48 [path curveToPoint:bottomLeft | |
49 controlPoint1:NSMakePoint(midLeft2.x, bottomLeft.y) | |
50 controlPoint2:NSMakePoint(midLeft2.x, bottomLeft.y)]; | |
51 | |
52 [path lineToPoint:bottomRight]; | |
53 [path curveToPoint:midRight1 | |
54 controlPoint1:NSMakePoint(midRight1.x, bottomLeft.y) | |
55 controlPoint2:NSMakePoint(midRight1.x, bottomLeft.y)]; | |
56 [path lineToPoint:midRight2]; | |
57 [path curveToPoint:topRight | |
58 controlPoint1:NSMakePoint(midRight2.x, topLeft.y) | |
59 controlPoint2:NSMakePoint(midRight2.x, topLeft.y)]; | |
60 NSGraphicsContext* context = [NSGraphicsContext currentContext]; | |
61 [context saveGraphicsState]; | |
62 [path addClip]; | |
63 | |
64 // Set the pattern phase | |
65 NSPoint phase = [[self window] themePatternPhase]; | |
66 | |
67 [context setPatternPhase:phase]; | |
68 [super drawBackground]; | |
69 [context restoreGraphicsState]; | |
70 | |
71 [[self strokeColor] set]; | |
72 [path stroke]; | |
73 } | |
74 | |
75 // The findbar is mostly opaque, but has an 8px transparent border on the left | |
76 // and right sides (see |kCurveSize|). This is an artifact of the way it is | |
77 // drawn. We override hitTest to return nil for points in this transparent | |
78 // area. | |
79 - (NSView*)hitTest:(NSPoint)point { | |
80 NSView* hitView = [super hitTest:point]; | |
81 if (hitView == self) { | |
82 // |rect| is approximately equivalent to the opaque area of the findbar. | |
83 NSRect rect = NSInsetRect([self bounds], kCurveSize, 0); | |
84 if (!NSMouseInRect(point, rect, [self isFlipped])) | |
85 return nil; | |
86 } | |
87 | |
88 return hitView; | |
89 } | |
90 | |
91 // Eat all mouse events, to prevent clicks from falling through to views below. | |
92 - (void)mouseDown:(NSEvent *)theEvent { | |
93 } | |
94 | |
95 - (void)rightMouseDown:(NSEvent *)theEvent { | |
96 } | |
97 | |
98 - (void)otherMouseDown:(NSEvent *)theEvent { | |
99 } | |
100 | |
101 - (void)mouseUp:(NSEvent *)theEvent { | |
102 } | |
103 | |
104 - (void)rightMouseUp:(NSEvent *)theEvent { | |
105 } | |
106 | |
107 - (void)otherMouseUp:(NSEvent *)theEvent { | |
108 } | |
109 | |
110 - (void)mouseMoved:(NSEvent *)theEvent { | |
111 } | |
112 | |
113 - (void)mouseDragged:(NSEvent *)theEvent { | |
114 } | |
115 | |
116 - (void)rightMouseDragged:(NSEvent *)theEvent { | |
117 } | |
118 | |
119 - (void)otherMouseDragged:(NSEvent *)theEvent { | |
120 } | |
121 | |
122 // Eat drag operations, to prevent drags from going through to the views below. | |
123 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info { | |
124 return NSDragOperationNone; | |
125 } | |
126 | |
127 - (ViewID)viewID { | |
128 return VIEW_ID_FIND_IN_PAGE; | |
129 } | |
130 | |
131 @end | |
OLD | NEW |