location_bar_decoration.h revision 21d179b334e59e9a3bfcaed4c4430bef1bc5759d
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#ifndef CHROME_BROWSER_UI_COCOA_LOCATION_BAR_LOCATION_BAR_DECORATION_H_
6#define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_LOCATION_BAR_DECORATION_H_
7#pragma once
8
9#import <Cocoa/Cocoa.h>
10
11#import "base/basictypes.h"
12
13// Base class for decorations at the left and right of the location
14// bar.  For instance, the location icon.
15
16// |LocationBarDecoration| and subclasses should approximately
17// parallel the classes provided under views/location_bar/.  The term
18// "decoration" is used because "view" has strong connotations in
19// Cocoa, and while these are view-like, they aren't views at all.
20// Decorations are more like Cocoa cells, except implemented in C++ to
21// allow more similarity to the other platform implementations.
22
23class LocationBarDecoration {
24 public:
25  LocationBarDecoration()
26      : visible_(false) {
27  }
28  virtual ~LocationBarDecoration() {}
29
30  // Determines whether the decoration is visible.
31  virtual bool IsVisible() const {
32    return visible_;
33  }
34  virtual void SetVisible(bool visible) {
35    visible_ = visible;
36  }
37
38  // Decorations can change their size to fit the available space.
39  // Returns the width the decoration will use in the space allotted,
40  // or |kOmittedWidth| if it should be omitted.
41  virtual CGFloat GetWidthForSpace(CGFloat width);
42
43  // Draw the decoration in the frame provided.  The frame will be
44  // generated from an earlier call to |GetWidthForSpace()|.
45  virtual void DrawInFrame(NSRect frame, NSView* control_view);
46
47  // Returns the tooltip for this decoration, return |nil| for no tooltip.
48  virtual NSString* GetToolTip() { return nil; }
49
50  // Decorations which do not accept mouse events are treated like the
51  // field's background for purposes of selecting text.  When such
52  // decorations are adjacent to the text area, they will show the
53  // I-beam cursor.  Decorations which do accept mouse events will get
54  // an arrow cursor when the mouse is over them.
55  virtual bool AcceptsMousePress() { return false; }
56
57  // Determine if the item can act as a drag source.
58  virtual bool IsDraggable() { return false; }
59
60  // The image to drag.
61  virtual NSImage* GetDragImage() { return nil; }
62
63  // Return the place within the decoration's frame where the
64  // |GetDragImage()| comes from.  This is used to make sure the image
65  // appears correctly under the mouse while dragging.  |frame|
66  // matches the frame passed to |DrawInFrame()|.
67  virtual NSRect GetDragImageFrame(NSRect frame) { return NSZeroRect; }
68
69  // The pasteboard to drag.
70  virtual NSPasteboard* GetDragPasteboard() { return nil; }
71
72  // Called on mouse down.  Return |false| to indicate that the press
73  // was not processed and should be handled by the cell.
74  virtual bool OnMousePressed(NSRect frame) { return false; }
75
76  // Called to get the right-click menu, return |nil| for no menu.
77  virtual NSMenu* GetMenu() { return nil; }
78
79  // Width returned by |GetWidthForSpace()| when the item should be
80  // omitted for this width;
81  static const CGFloat kOmittedWidth;
82
83 private:
84  bool visible_;
85
86  DISALLOW_COPY_AND_ASSIGN(LocationBarDecoration);
87};
88
89#endif  // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_LOCATION_BAR_DECORATION_H_
90