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 - 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();
46 // The bubble only has a preferred height: the sum of the height of
47 // the font and kTotalVerticalPadding.
48 gfx::Size
GetPreferredSize();
50 // Set the bounds of the bubble relative to |base_view_|.
51 void SetBounds(int x
, int y
, int w
, int h
);
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 StatusViewExpander
;
73 // Initializes the popup and view.
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
);
80 // Returns true if the base_view_'s widget is visible and not minimized.
81 bool IsFrameVisible();
83 // Expand bubble size to accommodate a long URL.
86 // Cancel all waiting expansion animations in the timer.
87 void CancelExpandTimer();
89 // Get the standard width for a status bubble in the current frame size.
90 int GetStandardStatusBubbleWidth();
92 // Get the maximum possible width for a status bubble in the current frame
94 int GetMaxStatusBubbleWidth();
96 // The status text we want to display when there are no URLs to display.
97 base::string16 status_text_
;
99 // The url we want to display when there is no status text to display.
100 base::string16 url_text_
;
102 // The original, non-elided URL.
105 // Used to elide the original URL again when we expand it.
106 std::string languages_
;
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_
;
114 // Last location passed to MouseMoved().
115 gfx::Point last_mouse_moved_location_
;
117 // Whether the view contains the mouse.
118 bool contains_mouse_
;
120 // How vertically offset the bubble is from its root position_.
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_
;
128 views::View
* base_view_
;
131 // Manages the expansion of a status bubble to fit a long URL.
132 scoped_ptr
<StatusViewExpander
> expand_view_
;
134 // If the download shelf is visible, do not obscure it.
135 bool download_shelf_is_visible_
;
137 // If the bubble has already been expanded, and encounters a new URL,
138 // change size immediately, with no hover.
141 // Times expansion of status bubble when URL is too long for standard width.
142 base::WeakPtrFactory
<StatusBubbleViews
> expand_timer_factory_
;
144 DISALLOW_COPY_AND_ASSIGN(StatusBubbleViews
);
147 #endif // CHROME_BROWSER_UI_VIEWS_STATUS_BUBBLE_VIEWS_H_