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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_STATUS_BUBBLE_VIEWS_H_
6 #define CHROME_BROWSER_UI_VIEWS_STATUS_BUBBLE_VIEWS_H_
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"
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
{
30 // How wide the bubble's shadow is.
31 static const int kShadowThickness
;
33 // The combined vertical padding above and below the text.
34 static const int kTotalVerticalPadding
= 7;
36 // |base_view| is the view that this bubble is positioned relative to.
37 explicit StatusBubbleViews(views::View
* base_view
);
38 virtual ~StatusBubbleViews();
40 views::View
* base_view() { return base_view_
; }
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();
46 // The bubble only has a preferred height: the sum of the height of
47 // the font and kTotalVerticalPadding.
48 gfx::Size
GetPreferredSize();
50 // Calculate and set new position for status bubble.
53 // Set bubble to new width.
54 void SetBubbleWidth(int width
);
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
;
64 views::Widget
* GetPopupForTest() { return popup(); }
67 views::Widget
* popup() { return popup_
.get(); }
71 class StatusViewAnimation
;
72 class StatusViewExpander
;
74 // Initializes the popup and view.
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
);
81 // Returns true if the base_view_'s widget is visible and not minimized.
82 bool IsFrameVisible();
84 // Returns true if the base_view_'s widget is maximized.
85 bool IsFrameMaximized();
87 // Expand bubble size to accommodate a long URL.
90 // Cancel all waiting expansion animations in the timer.
91 void CancelExpandTimer();
93 // Get the standard width for a status bubble in the current frame size.
94 int GetStandardStatusBubbleWidth();
96 // Get the maximum possible width for a status bubble in the current frame
98 int GetMaxStatusBubbleWidth();
100 // Set the bounds of the bubble relative to |base_view_|.
101 void SetBounds(int x
, int y
, int w
, int h
);
103 // The status text we want to display when there are no URLs to display.
104 base::string16 status_text_
;
106 // The url we want to display when there is no status text to display.
107 base::string16 url_text_
;
109 // The original, non-elided URL.
112 // Used to elide the original URL again when we expand it.
113 std::string languages_
;
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_
;
121 // Last location passed to MouseMoved().
122 gfx::Point last_mouse_moved_location_
;
124 // Whether the view contains the mouse.
125 bool contains_mouse_
;
127 // How vertically offset the bubble is from its root position_.
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_
;
134 views::View
* base_view_
;
137 // Manages the expansion of a status bubble to fit a long URL.
138 scoped_ptr
<StatusViewExpander
> expand_view_
;
140 // If the download shelf is visible, do not obscure it.
141 bool download_shelf_is_visible_
;
143 // If the bubble has already been expanded, and encounters a new URL,
144 // change size immediately, with no hover.
147 // Times expansion of status bubble when URL is too long for standard width.
148 base::WeakPtrFactory
<StatusBubbleViews
> expand_timer_factory_
;
150 DISALLOW_COPY_AND_ASSIGN(StatusBubbleViews
);
153 #endif // CHROME_BROWSER_UI_VIEWS_STATUS_BUBBLE_VIEWS_H_