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