| 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" |
| 11 #include "chrome/browser/status_bubble.h" | 12 #include "chrome/browser/status_bubble.h" |
| 13 #include "googleurl/src/gurl.h" |
| 12 | 14 |
| 13 class GURL; | 15 class GURL; |
| 14 namespace views { | 16 namespace views { |
| 15 class Widget; | 17 class Widget; |
| 16 } | 18 } |
| 17 | 19 |
| 18 // StatusBubble displays a bubble of text that fades in, hovers over the | 20 // StatusBubble displays a bubble of text that fades in, hovers over the |
| 19 // browser chrome and fades away when not needed. It is primarily designed | 21 // browser chrome and fades away when not needed. It is primarily designed |
| 20 // to allow users to see where hovered links point to. | 22 // to allow users to see where hovered links point to. |
| 21 class StatusBubbleViews : public StatusBubble { | 23 class StatusBubbleViews : public StatusBubble { |
| 22 public: | 24 public: |
| 23 // How wide the bubble's shadow is. | 25 // How wide the bubble's shadow is. |
| 24 static const int kShadowThickness; | 26 static const int kShadowThickness; |
| 25 | 27 |
| 26 // The combined vertical padding above and below the text. | 28 // The combined vertical padding above and below the text. |
| 27 static const int kTotalVerticalPadding = 7; | 29 static const int kTotalVerticalPadding = 7; |
| 28 | 30 |
| 31 // On hover, expand status bubble to accommodate long URL after this delay. |
| 32 static const int kExpandHoverDelay = 2000; |
| 33 |
| 29 explicit StatusBubbleViews(views::Widget* frame); | 34 explicit StatusBubbleViews(views::Widget* frame); |
| 30 ~StatusBubbleViews(); | 35 ~StatusBubbleViews(); |
| 31 | 36 |
| 32 // Reposition the bubble - as we are using a WS_POPUP for the bubble, | 37 // Reposition the bubble - as we are using a WS_POPUP for the bubble, |
| 33 // we have to manually position it when the browser window moves. | 38 // we have to manually position it when the browser window moves. |
| 34 void Reposition(); | 39 void Reposition(); |
| 35 | 40 |
| 36 // The bubble only has a preferred height: the sum of the height of | 41 // The bubble only has a preferred height: the sum of the height of |
| 37 // the font and kTotalVerticalPadding. | 42 // the font and kTotalVerticalPadding. |
| 38 gfx::Size GetPreferredSize(); | 43 gfx::Size GetPreferredSize(); |
| 39 | 44 |
| 40 // Set the bounds of the bubble relative to the browser window. | 45 // Set the bounds of the bubble relative to the browser window. |
| 41 void SetBounds(int x, int y, int w, int h); | 46 void SetBounds(int x, int y, int w, int h); |
| 42 | 47 |
| 48 // Set bubble to new width; for animation of expansion. |
| 49 void SetBubbleWidth(int width); |
| 50 |
| 43 // Overridden from StatusBubble: | 51 // Overridden from StatusBubble: |
| 44 virtual void SetStatus(const std::wstring& status); | 52 virtual void SetStatus(const std::wstring& status); |
| 45 virtual void SetURL(const GURL& url, const std::wstring& languages); | 53 virtual void SetURL(const GURL& url, const std::wstring& languages); |
| 46 virtual void Hide(); | 54 virtual void Hide(); |
| 47 virtual void MouseMoved(); | 55 virtual void MouseMoved(); |
| 48 virtual void UpdateDownloadShelfVisibility(bool visible); | 56 virtual void UpdateDownloadShelfVisibility(bool visible); |
| 49 | 57 |
| 50 private: | 58 private: |
| 51 class StatusView; | 59 class StatusView; |
| 60 class StatusViewExpander; |
| 52 | 61 |
| 53 // Initializes the popup and view. | 62 // Initializes the popup and view. |
| 54 void Init(); | 63 void Init(); |
| 55 | 64 |
| 56 // Attempt to move the status bubble out of the way of the cursor, allowing | 65 // Attempt to move the status bubble out of the way of the cursor, allowing |
| 57 // users to see links in the region normally occupied by the status bubble. | 66 // users to see links in the region normally occupied by the status bubble. |
| 58 void AvoidMouse(); | 67 void AvoidMouse(); |
| 59 | 68 |
| 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 |
| 60 // The status text we want to display when there are no URLs to display. | 82 // The status text we want to display when there are no URLs to display. |
| 61 std::wstring status_text_; | 83 std::wstring status_text_; |
| 62 | 84 |
| 63 // The url we want to display when there is not status text to display. | 85 // The url we want to display when there is not status text to display. |
| 86 // This string may be elided if the URL is too long to fit in status bubble. |
| 64 std::wstring url_text_; | 87 std::wstring url_text_; |
| 65 | 88 |
| 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 |
| 66 // Position relative to the parent window. | 97 // Position relative to the parent window. |
| 67 gfx::Point position_; | 98 gfx::Point position_; |
| 68 gfx::Size size_; | 99 gfx::Size size_; |
| 69 | 100 |
| 70 // How vertically offset the bubble is from its root position_. | 101 // How vertically offset the bubble is from its root position_. |
| 71 int offset_; | 102 int offset_; |
| 72 | 103 |
| 73 // We use a HWND for the popup so that it may float above any HWNDs in our | 104 // We use a HWND for the popup so that it may float above any HWNDs in our |
| 74 // UI (the location bar, for example). | 105 // UI (the location bar, for example). |
| 75 scoped_ptr<views::Widget> popup_; | 106 scoped_ptr<views::Widget> popup_; |
| 76 double opacity_; | 107 double opacity_; |
| 77 | 108 |
| 78 views::Widget* frame_; | 109 views::Widget* frame_; |
| 79 StatusView* view_; | 110 StatusView* view_; |
| 111 StatusViewExpander* expand_view_; |
| 80 | 112 |
| 81 // If the download shelf is visible, do not obscure it. | 113 // If the download shelf is visible, do not obscure it. |
| 82 bool download_shelf_is_visible_; | 114 bool download_shelf_is_visible_; |
| 83 | 115 |
| 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 |
| 84 DISALLOW_COPY_AND_ASSIGN(StatusBubbleViews); | 122 DISALLOW_COPY_AND_ASSIGN(StatusBubbleViews); |
| 85 }; | 123 }; |
| 86 | 124 |
| 87 #endif // CHROME_BROWSER_VIEWS_STATUS_BUBBLE_VIEWS_H_ | 125 #endif // CHROME_BROWSER_VIEWS_STATUS_BUBBLE_VIEWS_H_ |
| OLD | NEW |