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

Side by Side Diff: chrome/browser/ui/views/bubble/bubble.cc

Issue 7015051: Re-land: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/ui/views/bubble/bubble.h" 5 #include "chrome/browser/ui/views/bubble/bubble.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "chrome/browser/ui/views/bubble/border_contents.h" 9 #include "chrome/browser/ui/views/bubble/border_contents.h"
10 #include "content/common/notification_service.h" 10 #include "content/common/notification_service.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // Also fade in/out the bubble border window. 114 // Also fade in/out the bubble border window.
115 border_->SetOpacity(opacity); 115 border_->SetOpacity(opacity);
116 border_->border_contents()->SchedulePaint(); 116 border_->border_contents()->SchedulePaint();
117 #else 117 #else
118 NOTIMPLEMENTED(); 118 NOTIMPLEMENTED();
119 #endif 119 #endif
120 } 120 }
121 121
122 Bubble::Bubble() 122 Bubble::Bubble()
123 : 123 :
124 #if defined(OS_WIN)
125 views::WidgetWin(new views::Widget),
126 #elif defined(TOOLKIT_USES_GTK)
127 views::WidgetGtk(new views::Widget),
128 #endif
124 #if defined(TOOLKIT_USES_GTK) 129 #if defined(TOOLKIT_USES_GTK)
125 border_contents_(NULL), 130 border_contents_(NULL),
126 #elif defined(OS_WIN) 131 #elif defined(OS_WIN)
127 border_(NULL), 132 border_(NULL),
128 #endif 133 #endif
129 delegate_(NULL), 134 delegate_(NULL),
130 show_status_(kOpen), 135 show_status_(kOpen),
131 fade_away_on_close_(false), 136 fade_away_on_close_(false),
132 #if defined(OS_LINUX) 137 #if defined(TOOLKIT_USES_GTK)
133 type_(views::Widget::InitParams::TYPE_WINDOW), 138 type_(views::Widget::InitParams::TYPE_WINDOW),
134 #endif 139 #endif
135 #if defined(OS_CHROMEOS) 140 #if defined(OS_CHROMEOS)
136 show_while_screen_is_locked_(false), 141 show_while_screen_is_locked_(false),
137 #endif 142 #endif
138 arrow_location_(BubbleBorder::NONE), 143 arrow_location_(BubbleBorder::NONE),
139 contents_(NULL) { 144 contents_(NULL) {
140 } 145 }
141 146
142 #if defined(OS_CHROMEOS) 147 #if defined(OS_CHROMEOS)
143 Bubble::Bubble(views::Widget::InitParams::Type type, 148 Bubble::Bubble(views::Widget::InitParams::Type type,
144 bool show_while_screen_is_locked) 149 bool show_while_screen_is_locked)
145 : border_contents_(NULL), 150 : views::WidgetGtk(new views::Widget),
151 border_contents_(NULL),
146 delegate_(NULL), 152 delegate_(NULL),
147 show_status_(kOpen), 153 show_status_(kOpen),
148 fade_away_on_close_(false), 154 fade_away_on_close_(false),
149 type_(type), 155 type_(type),
150 show_while_screen_is_locked_(show_while_screen_is_locked), 156 show_while_screen_is_locked_(show_while_screen_is_locked),
151 arrow_location_(BubbleBorder::NONE), 157 arrow_location_(BubbleBorder::NONE),
152 contents_(NULL) { 158 contents_(NULL) {
153 } 159 }
154 #endif 160 #endif
155 161
156 Bubble::~Bubble() { 162 Bubble::~Bubble() {
157 } 163 }
158 164
159 void Bubble::InitBubble(views::Widget* parent, 165 void Bubble::InitBubble(views::Widget* parent,
160 const gfx::Rect& position_relative_to, 166 const gfx::Rect& position_relative_to,
161 BubbleBorder::ArrowLocation arrow_location, 167 BubbleBorder::ArrowLocation arrow_location,
162 views::View* contents, 168 views::View* contents,
163 BubbleDelegate* delegate) { 169 BubbleDelegate* delegate) {
164 delegate_ = delegate; 170 delegate_ = delegate;
165 position_relative_to_ = position_relative_to; 171 position_relative_to_ = position_relative_to;
166 arrow_location_ = arrow_location; 172 arrow_location_ = arrow_location;
167 contents_ = contents; 173 contents_ = contents;
168 174
169 // Create the main window. 175 // Create the main window.
170 #if defined(OS_WIN) 176 #if defined(OS_WIN)
171 views::Window* parent_window = parent->GetWindow(); 177 views::Window* parent_window = parent->GetContainingWindow();
172 if (parent_window) 178 if (parent_window)
173 parent_window->DisableInactiveRendering(); 179 parent_window->DisableInactiveRendering();
174 set_window_style(WS_POPUP | WS_CLIPCHILDREN); 180 set_window_style(WS_POPUP | WS_CLIPCHILDREN);
175 int extended_style = WS_EX_TOOLWINDOW; 181 int extended_style = WS_EX_TOOLWINDOW;
176 // During FadeIn we need to turn on the layered window style to deal with 182 // During FadeIn we need to turn on the layered window style to deal with
177 // transparency. This flag needs to be reset after fading in is complete. 183 // transparency. This flag needs to be reset after fading in is complete.
178 bool fade_in = delegate_ && delegate_->FadeInOnShow(); 184 bool fade_in = delegate_ && delegate_->FadeInOnShow();
179 if (fade_in) 185 if (fade_in)
180 extended_style |= WS_EX_LAYERED; 186 extended_style |= WS_EX_LAYERED;
181 set_window_ex_style(extended_style); 187 set_window_ex_style(extended_style);
182 188
183 DCHECK(!border_); 189 DCHECK(!border_);
184 border_ = new BorderWidgetWin(); 190 border_ = new BorderWidgetWin();
185 191
186 if (fade_in) { 192 if (fade_in) {
187 border_->SetOpacity(0); 193 border_->SetOpacity(0);
188 SetOpacity(0); 194 GetWidget()->SetOpacity(0);
189 } 195 }
190 196
191 border_->InitBorderWidgetWin(CreateBorderContents(), parent->GetNativeView()); 197 border_->InitBorderWidgetWin(CreateBorderContents(), parent->GetNativeView());
192 border_->border_contents()->SetBackgroundColor(kBackgroundColor); 198 border_->border_contents()->SetBackgroundColor(kBackgroundColor);
193 199
194 // We make the BorderWidgetWin the owner of the Bubble HWND, so that the 200 // We make the BorderWidgetWin the owner of the Bubble HWND, so that the
195 // latter is displayed on top of the former. 201 // latter is displayed on top of the former.
196 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); 202 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
197 params.parent = border_->GetNativeView(); 203 params.parent = border_->GetNativeView();
204 params.native_widget = this;
198 GetWidget()->Init(params); 205 GetWidget()->Init(params);
199 206
200 SetWindowText(GetNativeView(), delegate_->accessible_name().c_str()); 207 SetWindowText(GetNativeView(), delegate_->accessible_name().c_str());
201 #elif defined(TOOLKIT_USES_GTK) 208 #elif defined(TOOLKIT_USES_GTK)
202 views::Widget::InitParams params(type_); 209 views::Widget::InitParams params(type_);
203 params.transparent = true; 210 params.transparent = true;
204 params.parent_widget = parent; 211 params.parent_widget = parent;
205 // TODO(beng): Figure out how to make this implicit or set via InitParams. 212 params.native_widget = this;
206 make_transient_to_parent();
207 GetWidget()->Init(params); 213 GetWidget()->Init(params);
208 #if defined(OS_CHROMEOS) 214 #if defined(OS_CHROMEOS)
209 { 215 {
210 vector<int> params; 216 vector<int> params;
211 params.push_back(show_while_screen_is_locked_ ? 1 : 0); 217 params.push_back(show_while_screen_is_locked_ ? 1 : 0);
212 chromeos::WmIpc::instance()->SetWindowType( 218 chromeos::WmIpc::instance()->SetWindowType(
213 GetNativeView(), 219 GetNativeView(),
214 chromeos::WM_IPC_WINDOW_CHROME_INFO_BUBBLE, 220 chromeos::WM_IPC_WINDOW_CHROME_INFO_BUBBLE,
215 &params); 221 &params);
216 } 222 }
217 #endif 223 #endif
218 #endif 224 #endif
219 225
220 // Create a View to hold the contents of the main window. 226 // Create a View to hold the contents of the main window.
221 views::View* contents_view = new views::View; 227 views::View* contents_view = new views::View;
222 // We add |contents_view| to ourselves before the AddChildView() call below so 228 // We add |contents_view| to ourselves before the AddChildView() call below so
223 // that when |contents| gets added, it will already have a widget, and thus 229 // that when |contents| gets added, it will already have a widget, and thus
224 // any NativeButtons it creates in ViewHierarchyChanged() will be functional 230 // any NativeButtons it creates in ViewHierarchyChanged() will be functional
225 // (e.g. calling SetChecked() on checkboxes is safe). 231 // (e.g. calling SetChecked() on checkboxes is safe).
226 SetContentsView(contents_view); 232 GetWidget()->SetContentsView(contents_view);
227 // Adding |contents| as a child has to be done before we call 233 // Adding |contents| as a child has to be done before we call
228 // contents->GetPreferredSize() below, since some supplied views don't 234 // contents->GetPreferredSize() below, since some supplied views don't
229 // actually initialize themselves until they're added to a hierarchy. 235 // actually initialize themselves until they're added to a hierarchy.
230 contents_view->AddChildView(contents); 236 contents_view->AddChildView(contents);
231 237
232 // Calculate and set the bounds for all windows and views. 238 // Calculate and set the bounds for all windows and views.
233 gfx::Rect window_bounds; 239 gfx::Rect window_bounds;
234 240
235 #if defined(OS_WIN) 241 #if defined(OS_WIN)
236 // Initialize and position the border window. 242 // Initialize and position the border window.
(...skipping 18 matching lines...) Expand all
255 &contents_bounds, &window_bounds); 261 &contents_bounds, &window_bounds);
256 // This new view must be added before |contents| so it will paint under it. 262 // This new view must be added before |contents| so it will paint under it.
257 contents_view->AddChildViewAt(border_contents_, 0); 263 contents_view->AddChildViewAt(border_contents_, 0);
258 264
259 // |contents_view| has no layout manager, so we have to explicitly position 265 // |contents_view| has no layout manager, so we have to explicitly position
260 // its children. 266 // its children.
261 border_contents_->SetBoundsRect( 267 border_contents_->SetBoundsRect(
262 gfx::Rect(gfx::Point(), window_bounds.size())); 268 gfx::Rect(gfx::Point(), window_bounds.size()));
263 contents->SetBoundsRect(contents_bounds); 269 contents->SetBoundsRect(contents_bounds);
264 #endif 270 #endif
265 SetBounds(window_bounds); 271 GetWidget()->SetBounds(window_bounds);
266 272
267 // Register the Escape accelerator for closing. 273 // Register the Escape accelerator for closing.
268 GetFocusManager()->RegisterAccelerator( 274 GetWidget()->GetFocusManager()->RegisterAccelerator(
269 views::Accelerator(ui::VKEY_ESCAPE, false, false, false), this); 275 views::Accelerator(ui::VKEY_ESCAPE, false, false, false), this);
270 276
271 // Done creating the bubble. 277 // Done creating the bubble.
272 NotificationService::current()->Notify(NotificationType::INFO_BUBBLE_CREATED, 278 NotificationService::current()->Notify(NotificationType::INFO_BUBBLE_CREATED,
273 Source<Bubble>(this), 279 Source<Bubble>(this),
274 NotificationService::NoDetails()); 280 NotificationService::NoDetails());
275 281
276 // Show the window. 282 // Show the window.
277 #if defined(OS_WIN) 283 #if defined(OS_WIN)
278 border_->ShowWindow(SW_SHOW); 284 border_->ShowWindow(SW_SHOW);
279 ShowWindow(SW_SHOW); 285 ShowWindow(SW_SHOW);
280 if (fade_in) 286 if (fade_in)
281 FadeIn(); 287 FadeIn();
282 #elif defined(TOOLKIT_USES_GTK) 288 #elif defined(TOOLKIT_USES_GTK)
283 views::WidgetGtk::Show(); 289 GetWidget()->Show();
284 #endif 290 #endif
285 } 291 }
286 292
287 BorderContents* Bubble::CreateBorderContents() { 293 BorderContents* Bubble::CreateBorderContents() {
288 return new BorderContents(); 294 return new BorderContents();
289 } 295 }
290 296
291 void Bubble::SizeToContents() { 297 void Bubble::SizeToContents() {
292 gfx::Rect window_bounds; 298 gfx::Rect window_bounds;
293 299
294 #if defined(OS_WIN) 300 #if defined(OS_WIN)
295 // Initialize and position the border window. 301 // Initialize and position the border window.
296 window_bounds = border_->SizeAndGetBounds(position_relative_to_, 302 window_bounds = border_->SizeAndGetBounds(position_relative_to_,
297 arrow_location_, 303 arrow_location_,
298 contents_->GetPreferredSize()); 304 contents_->GetPreferredSize());
299 #else 305 #else
300 gfx::Rect contents_bounds; 306 gfx::Rect contents_bounds;
301 border_contents_->SizeAndGetBounds(position_relative_to_, 307 border_contents_->SizeAndGetBounds(position_relative_to_,
302 arrow_location_, false, contents_->GetPreferredSize(), 308 arrow_location_, false, contents_->GetPreferredSize(),
303 &contents_bounds, &window_bounds); 309 &contents_bounds, &window_bounds);
304 // |contents_view| has no layout manager, so we have to explicitly position 310 // |contents_view| has no layout manager, so we have to explicitly position
305 // its children. 311 // its children.
306 border_contents_->SetBoundsRect( 312 border_contents_->SetBoundsRect(
307 gfx::Rect(gfx::Point(), window_bounds.size())); 313 gfx::Rect(gfx::Point(), window_bounds.size()));
308 contents_->SetBoundsRect(contents_bounds); 314 contents_->SetBoundsRect(contents_bounds);
309 #endif 315 #endif
310 SetBounds(window_bounds); 316 GetWidget()->SetBounds(window_bounds);
311 } 317 }
312 318
313 #if defined(OS_WIN) 319 #if defined(OS_WIN)
314 void Bubble::OnActivate(UINT action, BOOL minimized, HWND window) { 320 void Bubble::OnActivate(UINT action, BOOL minimized, HWND window) {
315 // The popup should close when it is deactivated. 321 // The popup should close when it is deactivated.
316 if (action == WA_INACTIVE) { 322 if (action == WA_INACTIVE) {
317 Close(); 323 GetWidget()->Close();
318 } else if (action == WA_ACTIVE) { 324 } else if (action == WA_ACTIVE) {
319 DCHECK(GetRootView()->has_children()); 325 DCHECK(GetWidget()->GetRootView()->has_children());
320 GetRootView()->GetChildViewAt(0)->RequestFocus(); 326 GetWidget()->GetRootView()->GetChildViewAt(0)->RequestFocus();
321 } 327 }
322 } 328 }
323 #elif defined(TOOLKIT_USES_GTK) 329 #elif defined(TOOLKIT_USES_GTK)
324 void Bubble::IsActiveChanged() { 330 void Bubble::IsActiveChanged() {
325 if (!IsActive()) 331 if (!GetWidget()->IsActive())
326 Close(); 332 GetWidget()->Close();
327 } 333 }
328 #endif 334 #endif
329 335
330 void Bubble::DoClose(bool closed_by_escape) { 336 void Bubble::DoClose(bool closed_by_escape) {
331 if (show_status_ == kClosed) 337 if (show_status_ == kClosed)
332 return; 338 return;
333 339
334 GetFocusManager()->UnregisterAccelerator( 340 GetWidget()->GetFocusManager()->UnregisterAccelerator(
335 views::Accelerator(ui::VKEY_ESCAPE, false, false, false), this); 341 views::Accelerator(ui::VKEY_ESCAPE, false, false, false), this);
336 if (delegate_) 342 if (delegate_)
337 delegate_->BubbleClosing(this, closed_by_escape); 343 delegate_->BubbleClosing(this, closed_by_escape);
338 show_status_ = kClosed; 344 show_status_ = kClosed;
339 #if defined(OS_WIN) 345 #if defined(OS_WIN)
340 border_->Close(); 346 border_->Close();
347 #endif
348 #if defined(OS_WIN)
341 WidgetWin::Close(); 349 WidgetWin::Close();
342 #elif defined(TOOLKIT_USES_GTK) 350 #elif defined(TOOLKIT_USES_GTK)
343 WidgetGtk::Close(); 351 WidgetGtk::Close();
344 #endif 352 #endif
345 } 353 }
346 354
347 void Bubble::FadeIn() { 355 void Bubble::FadeIn() {
348 Fade(true); // |fade_in|. 356 Fade(true); // |fade_in|.
349 } 357 }
350 358
(...skipping 23 matching lines...) Expand all
374 animation_->Hide(); 382 animation_->Hide();
375 } 383 }
376 384
377 bool Bubble::AcceleratorPressed(const views::Accelerator& accelerator) { 385 bool Bubble::AcceleratorPressed(const views::Accelerator& accelerator) {
378 if (!delegate_ || delegate_->CloseOnEscape()) { 386 if (!delegate_ || delegate_->CloseOnEscape()) {
379 DoClose(true); 387 DoClose(true);
380 return true; 388 return true;
381 } 389 }
382 return false; 390 return false;
383 } 391 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bubble/border_widget_win.cc ('k') | chrome/browser/ui/views/constrained_html_delegate_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698