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/geometry/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 ~StatusBubbleViews() override
;
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 void SetStatus(const base::string16
& status
) override
;
58 void SetURL(const GURL
& url
, const std::string
& languages
) override
;
60 void MouseMoved(const gfx::Point
& location
, bool left_content
) override
;
61 void UpdateDownloadShelfVisibility(bool visible
) override
;
64 views::Widget
* popup() { return popup_
.get(); }
68 class StatusViewAnimation
;
69 class StatusViewExpander
;
71 // Initializes the popup and view.
74 // Attempt to move the status bubble out of the way of the cursor, allowing
75 // users to see links in the region normally occupied by the status bubble.
76 void AvoidMouse(const gfx::Point
& location
);
78 // Returns true if the base_view_'s widget is visible and not minimized.
79 bool IsFrameVisible();
81 // Returns true if the base_view_'s widget is maximized.
82 bool IsFrameMaximized();
84 // Expand bubble size to accommodate a long URL.
87 // Cancel all waiting expansion animations in the timer.
88 void CancelExpandTimer();
90 // Get the standard width for a status bubble in the current frame size.
91 int GetStandardStatusBubbleWidth();
93 // Get the maximum possible width for a status bubble in the current frame
95 int GetMaxStatusBubbleWidth();
97 // Set the bounds of the bubble relative to |base_view_|.
98 void SetBounds(int x
, int y
, int w
, int h
);
100 // The status text we want to display when there are no URLs to display.
101 base::string16 status_text_
;
103 // The url we want to display when there is no status text to display.
104 base::string16 url_text_
;
106 // The original, non-elided URL.
109 // Used to elide the original URL again when we expand it.
110 std::string languages_
;
112 // Position relative to the base_view_.
113 gfx::Point original_position_
;
114 // original_position_ adjusted according to the current RTL.
115 gfx::Point position_
;
118 // Last location passed to MouseMoved().
119 gfx::Point last_mouse_moved_location_
;
121 // Whether the view contains the mouse.
122 bool contains_mouse_
;
124 // How vertically offset the bubble is from its root position_.
127 // We use a HWND for the popup so that it may float above any HWNDs in our
128 // UI (the location bar, for example).
129 scoped_ptr
<views::Widget
> popup_
;
131 views::View
* base_view_
;
134 // Manages the expansion of a status bubble to fit a long URL.
135 scoped_ptr
<StatusViewExpander
> expand_view_
;
137 // If the download shelf is visible, do not obscure it.
138 bool download_shelf_is_visible_
;
140 // If the bubble has already been expanded, and encounters a new URL,
141 // change size immediately, with no hover.
144 // Times expansion of status bubble when URL is too long for standard width.
145 base::WeakPtrFactory
<StatusBubbleViews
> expand_timer_factory_
;
147 DISALLOW_COPY_AND_ASSIGN(StatusBubbleViews
);
150 #endif // CHROME_BROWSER_UI_VIEWS_STATUS_BUBBLE_VIEWS_H_