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