Home | History | Annotate | Download | only in location_bar
      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 
     23 class 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   virtual void SetVisible(bool visible);
     33 
     34   // Decorations can change their size to fit the available space.
     35   // Returns the width the decoration will use in the space allotted,
     36   // or |kOmittedWidth| if it should be omitted.
     37   virtual CGFloat GetWidthForSpace(CGFloat width);
     38 
     39   // Draw the decoration in the frame provided.  The frame will be
     40   // generated from an earlier call to |GetWidthForSpace()|.
     41   virtual void DrawInFrame(NSRect frame, NSView* control_view);
     42 
     43   // Returns the tooltip for this decoration, return |nil| for no tooltip.
     44   virtual NSString* GetToolTip();
     45 
     46   // Decorations which do not accept mouse events are treated like the
     47   // field's background for purposes of selecting text.  When such
     48   // decorations are adjacent to the text area, they will show the
     49   // I-beam cursor.  Decorations which do accept mouse events will get
     50   // an arrow cursor when the mouse is over them.
     51   virtual bool AcceptsMousePress();
     52 
     53   // Determine if the item can act as a drag source.
     54   virtual bool IsDraggable();
     55 
     56   // The image to drag.
     57   virtual NSImage* GetDragImage();
     58 
     59   // Return the place within the decoration's frame where the
     60   // |GetDragImage()| comes from.  This is used to make sure the image
     61   // appears correctly under the mouse while dragging.  |frame|
     62   // matches the frame passed to |DrawInFrame()|.
     63   virtual NSRect GetDragImageFrame(NSRect frame);
     64 
     65   // The pasteboard to drag.
     66   virtual NSPasteboard* GetDragPasteboard();
     67 
     68   // Called on mouse down.  Return |false| to indicate that the press
     69   // was not processed and should be handled by the cell.
     70   virtual bool OnMousePressed(NSRect frame);
     71 
     72   // Called to get the right-click menu, return |nil| for no menu.
     73   virtual NSMenu* GetMenu();
     74 
     75   // Width returned by |GetWidthForSpace()| when the item should be
     76   // omitted for this width;
     77   static const CGFloat kOmittedWidth;
     78 
     79  private:
     80   bool visible_;
     81 
     82   DISALLOW_COPY_AND_ASSIGN(LocationBarDecoration);
     83 };
     84 
     85 #endif  // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_LOCATION_BAR_DECORATION_H_
     86