status_bubble_views.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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
17namespace gfx {
18class Point;
19}
20namespace views {
21class View;
22class 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.
28class 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's popup - as we are using a WS_POPUP for the bubble,
43  // we have to manually position it when the browser window moves.
44  void RepositionPopup();
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  // Calculate and set new position for status bubble.
51  void Reposition();
52
53  // Set bubble to new width.
54  void SetBubbleWidth(int width);
55
56  // Overridden from StatusBubble:
57  virtual void SetStatus(const base::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 StatusViewAnimation;
72  class StatusViewExpander;
73
74  // Initializes the popup and view.
75  void Init();
76
77  // Attempt to move the status bubble out of the way of the cursor, allowing
78  // users to see links in the region normally occupied by the status bubble.
79  void AvoidMouse(const gfx::Point& location);
80
81  // Returns true if the base_view_'s widget is visible and not minimized.
82  bool IsFrameVisible();
83
84  // Returns true if the base_view_'s widget is maximized.
85  bool IsFrameMaximized();
86
87  // Expand bubble size to accommodate a long URL.
88  void ExpandBubble();
89
90  // Cancel all waiting expansion animations in the timer.
91  void CancelExpandTimer();
92
93  // Get the standard width for a status bubble in the current frame size.
94  int GetStandardStatusBubbleWidth();
95
96  // Get the maximum possible width for a status bubble in the current frame
97  // size.
98  int GetMaxStatusBubbleWidth();
99
100  // Set the bounds of the bubble relative to |base_view_|.
101  void SetBounds(int x, int y, int w, int h);
102
103  // The status text we want to display when there are no URLs to display.
104  base::string16 status_text_;
105
106  // The url we want to display when there is no status text to display.
107  base::string16 url_text_;
108
109  // The original, non-elided URL.
110  GURL url_;
111
112  // Used to elide the original URL again when we expand it.
113  std::string languages_;
114
115  // Position relative to the base_view_.
116  gfx::Point original_position_;
117  // original_position_ adjusted according to the current RTL.
118  gfx::Point position_;
119  gfx::Size size_;
120
121  // Last location passed to MouseMoved().
122  gfx::Point last_mouse_moved_location_;
123
124  // Whether the view contains the mouse.
125  bool contains_mouse_;
126
127  // How vertically offset the bubble is from its root position_.
128  int offset_;
129
130  // We use a HWND for the popup so that it may float above any HWNDs in our
131  // UI (the location bar, for example).
132  scoped_ptr<views::Widget> popup_;
133  double opacity_;
134
135  views::View* base_view_;
136  StatusView* view_;
137
138  // Manages the expansion of a status bubble to fit a long URL.
139  scoped_ptr<StatusViewExpander> expand_view_;
140
141  // If the download shelf is visible, do not obscure it.
142  bool download_shelf_is_visible_;
143
144  // If the bubble has already been expanded, and encounters a new URL,
145  // change size immediately, with no hover.
146  bool is_expanded_;
147
148  // Times expansion of status bubble when URL is too long for standard width.
149  base::WeakPtrFactory<StatusBubbleViews> expand_timer_factory_;
150
151  DISALLOW_COPY_AND_ASSIGN(StatusBubbleViews);
152};
153
154#endif  // CHROME_BROWSER_UI_VIEWS_STATUS_BUBBLE_VIEWS_H_
155