| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_VIEWS_STATUS_BUBBLE_VIEWS_H_ | 5 #ifndef CHROME_BROWSER_VIEWS_STATUS_BUBBLE_VIEWS_H_ |
| 6 #define CHROME_BROWSER_VIEWS_STATUS_BUBBLE_VIEWS_H_ | 6 #define CHROME_BROWSER_VIEWS_STATUS_BUBBLE_VIEWS_H_ |
| 7 | 7 |
| 8 #include "base/gfx/rect.h" | 8 #include "base/gfx/rect.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 11 #include "base/task.h" | |
| 12 #include "chrome/browser/status_bubble.h" | 11 #include "chrome/browser/status_bubble.h" |
| 13 #include "googleurl/src/gurl.h" | |
| 14 | 12 |
| 15 class GURL; | 13 class GURL; |
| 16 namespace views { | 14 namespace views { |
| 17 class Widget; | 15 class Widget; |
| 18 } | 16 } |
| 19 | 17 |
| 20 // StatusBubble displays a bubble of text that fades in, hovers over the | 18 // StatusBubble displays a bubble of text that fades in, hovers over the |
| 21 // browser chrome and fades away when not needed. It is primarily designed | 19 // browser chrome and fades away when not needed. It is primarily designed |
| 22 // to allow users to see where hovered links point to. | 20 // to allow users to see where hovered links point to. |
| 23 class StatusBubbleViews : public StatusBubble { | 21 class StatusBubbleViews : public StatusBubble { |
| 24 public: | 22 public: |
| 25 // How wide the bubble's shadow is. | 23 // How wide the bubble's shadow is. |
| 26 static const int kShadowThickness; | 24 static const int kShadowThickness; |
| 27 | 25 |
| 28 // The combined vertical padding above and below the text. | 26 // The combined vertical padding above and below the text. |
| 29 static const int kTotalVerticalPadding = 7; | 27 static const int kTotalVerticalPadding = 7; |
| 30 | 28 |
| 31 // On hover, expand status bubble to accommodate long URL after this delay. | |
| 32 static const int kExpandHoverDelay = 2000; | |
| 33 | |
| 34 explicit StatusBubbleViews(views::Widget* frame); | 29 explicit StatusBubbleViews(views::Widget* frame); |
| 35 ~StatusBubbleViews(); | 30 ~StatusBubbleViews(); |
| 36 | 31 |
| 37 // Reposition the bubble - as we are using a WS_POPUP for the bubble, | 32 // Reposition the bubble - as we are using a WS_POPUP for the bubble, |
| 38 // we have to manually position it when the browser window moves. | 33 // we have to manually position it when the browser window moves. |
| 39 void Reposition(); | 34 void Reposition(); |
| 40 | 35 |
| 41 // The bubble only has a preferred height: the sum of the height of | 36 // The bubble only has a preferred height: the sum of the height of |
| 42 // the font and kTotalVerticalPadding. | 37 // the font and kTotalVerticalPadding. |
| 43 gfx::Size GetPreferredSize(); | 38 gfx::Size GetPreferredSize(); |
| 44 | 39 |
| 45 // Set the bounds of the bubble relative to the browser window. | 40 // Set the bounds of the bubble relative to the browser window. |
| 46 void SetBounds(int x, int y, int w, int h); | 41 void SetBounds(int x, int y, int w, int h); |
| 47 | 42 |
| 48 // Set bubble to new width; for animation of expansion. | |
| 49 void SetBubbleWidth(int width); | |
| 50 | |
| 51 // Overridden from StatusBubble: | 43 // Overridden from StatusBubble: |
| 52 virtual void SetStatus(const std::wstring& status); | 44 virtual void SetStatus(const std::wstring& status); |
| 53 virtual void SetURL(const GURL& url, const std::wstring& languages); | 45 virtual void SetURL(const GURL& url, const std::wstring& languages); |
| 54 virtual void Hide(); | 46 virtual void Hide(); |
| 55 virtual void MouseMoved(); | 47 virtual void MouseMoved(); |
| 56 virtual void UpdateDownloadShelfVisibility(bool visible); | 48 virtual void UpdateDownloadShelfVisibility(bool visible); |
| 57 | 49 |
| 58 private: | 50 private: |
| 59 class StatusView; | 51 class StatusView; |
| 60 class StatusViewExpander; | |
| 61 | 52 |
| 62 // Initializes the popup and view. | 53 // Initializes the popup and view. |
| 63 void Init(); | 54 void Init(); |
| 64 | 55 |
| 65 // Attempt to move the status bubble out of the way of the cursor, allowing | 56 // Attempt to move the status bubble out of the way of the cursor, allowing |
| 66 // users to see links in the region normally occupied by the status bubble. | 57 // users to see links in the region normally occupied by the status bubble. |
| 67 void AvoidMouse(); | 58 void AvoidMouse(); |
| 68 | 59 |
| 69 // Expand bubble size to accommodate an abridged URL. | |
| 70 void ExpandBubble(); | |
| 71 | |
| 72 // Cancel all the expansions waiting in the timer. | |
| 73 void CancelExpandTimer(); | |
| 74 | |
| 75 // Get the standard width for a status bubble in the current frame size. | |
| 76 int GetStandardStatusBubbleWidth(); | |
| 77 | |
| 78 // Get the maximum possible width for a status bubble in the current | |
| 79 // frame size. | |
| 80 int GetMaxStatusBubbleWidth(); | |
| 81 | |
| 82 // The status text we want to display when there are no URLs to display. | 60 // The status text we want to display when there are no URLs to display. |
| 83 std::wstring status_text_; | 61 std::wstring status_text_; |
| 84 | 62 |
| 85 // The url we want to display when there is no status text to display. | 63 // The url we want to display when there is no status text to display. |
| 86 // This string may be elided if the URL is too long to fit in status bubble. | |
| 87 std::wstring url_text_; | 64 std::wstring url_text_; |
| 88 | 65 |
| 89 // The original url. We need to keep this around to we can re-elide it to | |
| 90 // dynamically fit the bubble if we need to expand it to show a url that | |
| 91 // has been cut off. | |
| 92 GURL url_; | |
| 93 | |
| 94 // Keep this around so we can elide the original url when we expand it. | |
| 95 std::wstring languages_; | |
| 96 | |
| 97 // Position relative to the parent window. | 66 // Position relative to the parent window. |
| 98 gfx::Point position_; | 67 gfx::Point position_; |
| 99 gfx::Size size_; | 68 gfx::Size size_; |
| 100 | 69 |
| 101 // How vertically offset the bubble is from its root position_. | 70 // How vertically offset the bubble is from its root position_. |
| 102 int offset_; | 71 int offset_; |
| 103 | 72 |
| 104 // We use a HWND for the popup so that it may float above any HWNDs in our | 73 // We use a HWND for the popup so that it may float above any HWNDs in our |
| 105 // UI (the location bar, for example). | 74 // UI (the location bar, for example). |
| 106 scoped_ptr<views::Widget> popup_; | 75 scoped_ptr<views::Widget> popup_; |
| 107 double opacity_; | 76 double opacity_; |
| 108 | 77 |
| 109 views::Widget* frame_; | 78 views::Widget* frame_; |
| 110 StatusView* view_; | 79 StatusView* view_; |
| 111 StatusViewExpander* expand_view_; | |
| 112 | 80 |
| 113 // If the download shelf is visible, do not obscure it. | 81 // If the download shelf is visible, do not obscure it. |
| 114 bool download_shelf_is_visible_; | 82 bool download_shelf_is_visible_; |
| 115 | 83 |
| 116 // Is the bubble expanded? If so, change size immediately. | |
| 117 bool is_expanded_; | |
| 118 | |
| 119 // Times expansion of status bubble when URL is too long for standard width. | |
| 120 ScopedRunnableMethodFactory<StatusBubbleViews> expand_timer_factory_; | |
| 121 | |
| 122 DISALLOW_COPY_AND_ASSIGN(StatusBubbleViews); | 84 DISALLOW_COPY_AND_ASSIGN(StatusBubbleViews); |
| 123 }; | 85 }; |
| 124 | 86 |
| 125 #endif // CHROME_BROWSER_VIEWS_STATUS_BUBBLE_VIEWS_H_ | 87 #endif // CHROME_BROWSER_VIEWS_STATUS_BUBBLE_VIEWS_H_ |
| OLD | NEW |