Home | History | Annotate | Download | only in views
      1 // Copyright (c) 2012 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_VIEWS_STATUS_BUBBLE_VIEWS_H_
      6 #define CHROME_BROWSER_UI_VIEWS_STATUS_BUBBLE_VIEWS_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/compiler_specific.h"
     10 #include "base/memory/scoped_ptr.h"
     11 #include "base/memory/weak_ptr.h"
     12 #include "base/strings/string16.h"
     13 #include "chrome/browser/ui/status_bubble.h"
     14 #include "ui/gfx/rect.h"
     15 #include "url/gurl.h"
     16 
     17 namespace gfx {
     18 class Point;
     19 }
     20 namespace views {
     21 class View;
     22 class Widget;
     23 }
     24 
     25 // StatusBubble displays a bubble of text that fades in, hovers over the
     26 // browser chrome and fades away when not needed. It is primarily designed
     27 // to allow users to see where hovered links point to.
     28 class StatusBubbleViews : public StatusBubble {
     29  public:
     30   // How wide the bubble's shadow is.
     31   static const int kShadowThickness;
     32 
     33   // The combined vertical padding above and below the text.
     34   static const int kTotalVerticalPadding = 7;
     35 
     36   // |base_view| is the view that this bubble is positioned relative to.
     37   explicit StatusBubbleViews(views::View* base_view);
     38   virtual ~StatusBubbleViews();
     39 
     40   views::View* base_view() { return base_view_; }
     41 
     42   // Reposition the bubble - as we are using a WS_POPUP for the bubble,
     43   // we have to manually position it when the browser window moves.
     44   virtual void Reposition();
     45 
     46   // The bubble only has a preferred height: the sum of the height of
     47   // the font and kTotalVerticalPadding.
     48   gfx::Size GetPreferredSize();
     49 
     50   // Set the bounds of the bubble relative to |base_view_|.
     51   void SetBounds(int x, int y, int w, int h);
     52 
     53   // Set bubble to new width.
     54   void SetBubbleWidth(int width);
     55 
     56   // Overridden from StatusBubble:
     57   virtual void SetStatus(const string16& status) OVERRIDE;
     58   virtual void SetURL(const GURL& url, const std::string& languages) OVERRIDE;
     59   virtual void Hide() OVERRIDE;
     60   virtual void MouseMoved(const gfx::Point& location,
     61                           bool left_content) OVERRIDE;
     62   virtual void UpdateDownloadShelfVisibility(bool visible) OVERRIDE;
     63 
     64   views::Widget* GetPopupForTest() { return popup(); }
     65 
     66  protected:
     67   views::Widget* popup() { return popup_.get(); }
     68 
     69  private:
     70   class StatusView;
     71   class StatusViewExpander;
     72 
     73   // Initializes the popup and view.
     74   void Init();
     75 
     76   // Attempt to move the status bubble out of the way of the cursor, allowing
     77   // users to see links in the region normally occupied by the status bubble.
     78   void AvoidMouse(const gfx::Point& location);
     79 
     80   // Returns true if the base_view_'s widget is visible and not minimized.
     81   bool IsFrameVisible();
     82 
     83   // Expand bubble size to accommodate a long URL.
     84   void ExpandBubble();
     85 
     86   // Cancel all waiting expansion animations in the timer.
     87   void CancelExpandTimer();
     88 
     89   // Get the standard width for a status bubble in the current frame size.
     90   int GetStandardStatusBubbleWidth();
     91 
     92   // Get the maximum possible width for a status bubble in the current frame
     93   // size.
     94   int GetMaxStatusBubbleWidth();
     95 
     96   // The status text we want to display when there are no URLs to display.
     97   string16 status_text_;
     98 
     99   // The url we want to display when there is no status text to display.
    100   string16 url_text_;
    101 
    102   // The original, non-elided URL.
    103   GURL url_;
    104 
    105   // Used to elide the original URL again when we expand it.
    106   std::string languages_;
    107 
    108   // Position relative to the base_view_.
    109   gfx::Point original_position_;
    110   // original_position_ adjusted according to the current RTL.
    111   gfx::Point position_;
    112   gfx::Size size_;
    113 
    114   // Last location passed to MouseMoved().
    115   gfx::Point last_mouse_moved_location_;
    116 
    117   // Whether the view contains the mouse.
    118   bool contains_mouse_;
    119 
    120   // How vertically offset the bubble is from its root position_.
    121   int offset_;
    122 
    123   // We use a HWND for the popup so that it may float above any HWNDs in our
    124   // UI (the location bar, for example).
    125   scoped_ptr<views::Widget> popup_;
    126   double opacity_;
    127 
    128   views::View* base_view_;
    129   StatusView* view_;
    130 
    131   // Manages the expansion of a status bubble to fit a long URL.
    132   scoped_ptr<StatusViewExpander> expand_view_;
    133 
    134   // If the download shelf is visible, do not obscure it.
    135   bool download_shelf_is_visible_;
    136 
    137   // If the bubble has already been expanded, and encounters a new URL,
    138   // change size immediately, with no hover.
    139   bool is_expanded_;
    140 
    141   // Times expansion of status bubble when URL is too long for standard width.
    142   base::WeakPtrFactory<StatusBubbleViews> expand_timer_factory_;
    143 
    144   DISALLOW_COPY_AND_ASSIGN(StatusBubbleViews);
    145 };
    146 
    147 #endif  // CHROME_BROWSER_UI_VIEWS_STATUS_BUBBLE_VIEWS_H_
    148