Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(420)

Side by Side Diff: chrome/browser/views/info_bubble.h

Issue 195099: Convert InfoBubble to using BubbleBorder. This also replaces the border grap... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/views/bubble_border.cc ('k') | chrome/browser/views/info_bubble.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_INFO_BUBBLE_H_ 5 #ifndef CHROME_BROWSER_VIEWS_INFO_BUBBLE_H_
6 #define CHROME_BROWSER_VIEWS_INFO_BUBBLE_H_ 6 #define CHROME_BROWSER_VIEWS_INFO_BUBBLE_H_
7 7
8 #include "views/view.h" 8 #include "chrome/browser/views/bubble_border.h"
9 9
10 #if defined(OS_WIN) 10 #if defined(OS_WIN)
11 #include "views/widget/widget_win.h" 11 #include "views/widget/widget_win.h"
12 #elif defined(OS_LINUX) 12 #elif defined(OS_LINUX)
13 #include "views/widget/widget_gtk.h" 13 #include "views/widget/widget_gtk.h"
14 #endif 14 #endif
15 15
16 // InfoBubble is used to display an arbitrary view above all other windows. 16 // InfoBubble is used to display an arbitrary view above all other windows.
17 // Think of InfoBubble as a tooltip that allows you to embed an arbitrary view 17 // Think of InfoBubble as a tooltip that allows you to embed an arbitrary view
18 // in the tooltip. Additionally the InfoBubble renders an arrow pointing at 18 // in the tooltip. Additionally the InfoBubble renders an arrow pointing at
19 // the region the info bubble is providing the information about. 19 // the region the info bubble is providing the information about.
20 // 20 //
21 // To use an InfoBubble, invoke Show() and it'll take care of the rest. The 21 // To use an InfoBubble, invoke Show() and it'll take care of the rest. The
22 // InfoBubble insets the contents for you, so the contents typically shouldn't 22 // InfoBubble insets the contents for you, so the contents typically shouldn't
23 // have any additional margins. 23 // have any additional margins.
24 24
25 class BorderWidget;
25 class InfoBubble; 26 class InfoBubble;
26 27
27 namespace views { 28 namespace views {
28 class Window; 29 class Window;
29 } 30 }
30 31
31 namespace gfx { 32 namespace gfx {
32 class Path; 33 class Path;
33 } 34 }
34 35
36 #if defined(OS_WIN)
37 // This is a window that surrounds the info bubble and paints the margin and
38 // border. It is a separate window so that it can be a layered window, so that
39 // we can use >1-bit alpha shadow images on the borders, which look nicer than
40 // the Windows CS_DROPSHADOW shadows. The info bubble window itself cannot be a
41 // layered window because that prevents it from hosting native child controls.
42 class BorderWidget : public views::WidgetWin {
43 public:
44 BorderWidget();
45 virtual ~BorderWidget() { }
46
47 // Given the owning (parent) window, the size of the contained contents
48 // (without margins), and the rect (in screen coordinates) to point to,
49 // initializes the window and returns the bounds (in screen coordinates) the
50 // contents should use. |is_rtl| is supplied to
51 // BorderContents::InitAndGetBounds(), see its declaration for details.
52 gfx::Rect InitAndGetBounds(HWND owner,
53 const gfx::Rect& position_relative_to,
54 const gfx::Size& contents_size,
55 bool is_rtl);
56
57 private:
58 // Overridden from WidgetWin:
59 virtual LRESULT OnMouseActivate(HWND window,
60 UINT hit_test,
61 UINT mouse_message);
62
63 DISALLOW_COPY_AND_ASSIGN(BorderWidget);
64 };
65 #endif
66
35 class InfoBubbleDelegate { 67 class InfoBubbleDelegate {
36 public: 68 public:
37 // Called when the InfoBubble is closing and is about to be deleted. 69 // Called when the InfoBubble is closing and is about to be deleted.
38 // |closed_by_escape| is true if the close is the result of the user pressing 70 // |closed_by_escape| is true if the close is the result of the user pressing
39 // escape. 71 // escape.
40 virtual void InfoBubbleClosing(InfoBubble* info_bubble, 72 virtual void InfoBubbleClosing(InfoBubble* info_bubble,
41 bool closed_by_escape) = 0; 73 bool closed_by_escape) = 0;
42 74
43 // Whether the InfoBubble should be closed when the Esc key is pressed. 75 // Whether the InfoBubble should be closed when the Esc key is pressed.
44 virtual bool CloseOnEscape() = 0; 76 virtual bool CloseOnEscape() = 0;
(...skipping 18 matching lines...) Expand all
63 // when the Escape key is pressed (the default behavior). 95 // when the Escape key is pressed (the default behavior).
64 static InfoBubble* Show(views::Window* parent, 96 static InfoBubble* Show(views::Window* parent,
65 const gfx::Rect& position_relative_to, 97 const gfx::Rect& position_relative_to,
66 views::View* contents, 98 views::View* contents,
67 InfoBubbleDelegate* delegate); 99 InfoBubbleDelegate* delegate);
68 100
69 // Overridden from WidgetWin: 101 // Overridden from WidgetWin:
70 virtual void Close(); 102 virtual void Close();
71 103
72 protected: 104 protected:
73 // InfoBubble::CreateContentView() creates one of these. ContentView houses
74 // the supplied content as its only child view, renders the arrow/border of
75 // the bubble and sizes the content.
76 class ContentView : public views::View {
77 public:
78 // Possible edges the arrow is aligned along.
79 enum ArrowEdge {
80 TOP_LEFT = 0,
81 TOP_RIGHT = 1,
82 BOTTOM_LEFT = 2,
83 BOTTOM_RIGHT = 3
84 };
85
86 // Creates the ContentView. The supplied view is added as the only child of
87 // the ContentView.
88 ContentView(views::View* content, InfoBubble* host);
89
90 virtual ~ContentView() {}
91
92 // Returns the bounds for the window to contain this view.
93 //
94 // This invokes CalculateWindowBounds, if the returned bounds don't fit on
95 // the monitor containing position_relative_to, the arrow edge is adjusted.
96 virtual gfx::Rect CalculateWindowBoundsAndAjust(
97 const gfx::Rect& position_relative_to);
98
99 // Sets the edge the arrow is rendered at.
100 void SetArrowEdge(ArrowEdge arrow_edge) { arrow_edge_ = arrow_edge; }
101
102 // Returns the preferred size, which is the sum of the preferred size of
103 // the content and the border/arrow.
104 virtual gfx::Size GetPreferredSize();
105
106 // Positions the content relative to the border.
107 virtual void Layout();
108
109 // Return the mask for the content view.
110 void GetMask(const gfx::Size& size, gfx::Path* mask);
111
112 // Paints the background and arrow appropriately.
113 virtual void Paint(gfx::Canvas* canvas);
114
115 // Returns true if the arrow is positioned along the top edge of the
116 // view. If this returns false the arrow is positioned along the bottom
117 // edge.
118 bool IsTop() { return (arrow_edge_ & 2) == 0; }
119
120 // Returns true if the arrow is positioned along the left edge of the
121 // view. If this returns false the arrow is positioned along the right edge.
122 bool IsLeft() { return (arrow_edge_ & 1) == 0; }
123
124 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
125
126 private:
127 // Returns the bounds for the window containing us based on the current
128 // arrow edge.
129 gfx::Rect CalculateWindowBounds(const gfx::Rect& position_relative_to);
130
131 views::View* content_;
132
133 // Edge to draw the arrow at.
134 ArrowEdge arrow_edge_;
135
136 // The bubble we're in.
137 InfoBubble* host_;
138
139 DISALLOW_COPY_AND_ASSIGN(ContentView);
140 };
141
142 InfoBubble(); 105 InfoBubble();
143 virtual ~InfoBubble() {} 106 virtual ~InfoBubble() {}
144 107
145 // Creates the InfoBubble. 108 // Creates the InfoBubble.
146 void Init(views::Window* parent, 109 void Init(views::Window* parent,
147 const gfx::Rect& position_relative_to, 110 const gfx::Rect& position_relative_to,
148 views::View* contents, 111 views::View* contents,
149 InfoBubbleDelegate* delegate); 112 InfoBubbleDelegate* delegate);
150 113
151 // Creates and return a new ContentView containing content.
152 virtual ContentView* CreateContentView(views::View* content);
153
154 #if defined(OS_WIN) 114 #if defined(OS_WIN)
155 // Overridden from WidgetWin: 115 // Overridden from WidgetWin:
156 virtual void OnActivate(UINT action, BOOL minimized, HWND window); 116 virtual void OnActivate(UINT action, BOOL minimized, HWND window);
157 virtual void OnSize(UINT param, const CSize& size);
158 #elif defined(OS_LINUX)
159 // Overridden from WidgetGtk:
160 virtual void OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation);
161 #endif 117 #endif
162 118
163 private: 119 private:
164 // Closes the window notifying the delegate. |closed_by_escape| is true if 120 // Closes the window notifying the delegate. |closed_by_escape| is true if
165 // the close is the result of pressing escape. 121 // the close is the result of pressing escape.
166 void Close(bool closed_by_escape); 122 void Close(bool closed_by_escape);
167 123
168 // Overridden from WidgetWin/WidgetGtk: 124 // Overridden from WidgetWin/WidgetGtk:
169 virtual bool AcceleratorPressed(const views::Accelerator& accelerator); 125 virtual bool AcceleratorPressed(const views::Accelerator& accelerator);
170 126
171 // The delegate, if any. 127 // The delegate, if any.
172 InfoBubbleDelegate* delegate_; 128 InfoBubbleDelegate* delegate_;
173 129
174 // The window that this InfoBubble is parented to. 130 // The window that this InfoBubble is parented to.
175 views::Window* parent_; 131 views::Window* parent_;
176 132
177 // The content view contained by the infobubble. 133 #if defined(OS_WIN)
178 ContentView* content_view_; 134 // The window used to render the padding, border and arrow.
135 scoped_ptr<BorderWidget> border_;
136 #endif
179 137
180 // Have we been closed? 138 // Have we been closed?
181 bool closed_; 139 bool closed_;
182 140
183 DISALLOW_COPY_AND_ASSIGN(InfoBubble); 141 DISALLOW_COPY_AND_ASSIGN(InfoBubble);
184 }; 142 };
185 143
186 #endif // CHROME_BROWSER_VIEWS_INFO_BUBBLE_H_ 144 #endif // CHROME_BROWSER_VIEWS_INFO_BUBBLE_H_
OLDNEW
« no previous file with comments | « chrome/browser/views/bubble_border.cc ('k') | chrome/browser/views/info_bubble.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698