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

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

Issue 8416053: Gets Bubble to work on aura. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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 "chrome/common/chrome_notification_types.h" 10 #include "chrome/common/chrome_notification_types.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // that style prevents some bubble content from working properly. 104 // that style prevents some bubble content from working properly.
105 SetWindowLong(GWL_EXSTYLE, GetWindowLong(GWL_EXSTYLE) & ~WS_EX_LAYERED); 105 SetWindowLong(GWL_EXSTYLE, GetWindowLong(GWL_EXSTYLE) & ~WS_EX_LAYERED);
106 #endif 106 #endif
107 } 107 }
108 } 108 }
109 109
110 void Bubble::AnimationProgressed(const ui::Animation* animation) { 110 void Bubble::AnimationProgressed(const ui::Animation* animation) {
111 // Set the opacity for the main contents window. 111 // Set the opacity for the main contents window.
112 unsigned char opacity = static_cast<unsigned char>( 112 unsigned char opacity = static_cast<unsigned char>(
113 animation_->GetCurrentValue() * 255); 113 animation_->GetCurrentValue() * 255);
114 #if defined(USE_AURA) 114 #if defined(OS_WIN) && !defined(USE_AURA)
115 // TODO(beng):
116 (void)opacity;
117 NOTIMPLEMENTED();
118 #elif defined(OS_WIN)
119 SetLayeredWindowAttributes(GetNativeView(), 0, 115 SetLayeredWindowAttributes(GetNativeView(), 0,
120 static_cast<byte>(opacity), LWA_ALPHA); 116 static_cast<byte>(opacity), LWA_ALPHA);
121 contents_->SchedulePaint(); 117 contents_->SchedulePaint();
122 118
123 // Also fade in/out the bubble border window. 119 // Also fade in/out the bubble border window.
124 border_->SetOpacity(opacity); 120 border_->SetOpacity(opacity);
125 border_->border_contents()->SchedulePaint(); 121 border_->border_contents()->SchedulePaint();
126 #else 122 #else
127 SetOpacity(opacity); 123 SetOpacity(opacity);
128 border_contents_->SchedulePaint(); 124 border_contents_->SchedulePaint();
129 #endif 125 #endif
130 } 126 }
131 127
132 Bubble::Bubble() 128 Bubble::Bubble()
133 : 129 :
134 #if defined(USE_AURA) 130 #if defined(USE_AURA)
135 views::NativeWidgetAura(new views::Widget), 131 views::NativeWidgetAura(new views::Widget),
136 #elif defined(OS_WIN) 132 #elif defined(OS_WIN)
137 views::NativeWidgetWin(new views::Widget), 133 views::NativeWidgetWin(new views::Widget),
138 #elif defined(TOUCH_UI) 134 #elif defined(TOUCH_UI)
139 views::NativeWidgetViews(new views::Widget), 135 views::NativeWidgetViews(new views::Widget),
140 #elif defined(TOOLKIT_USES_GTK) 136 #elif defined(TOOLKIT_USES_GTK)
141 views::NativeWidgetGtk(new views::Widget), 137 views::NativeWidgetGtk(new views::Widget),
142 #endif 138 #endif
143 #if defined(USE_AURA) 139 #if defined(OS_WIN) && !defined(USE_AURA)
144 #elif defined(TOOLKIT_USES_GTK) 140 border_(NULL),
141 #else
145 border_contents_(NULL), 142 border_contents_(NULL),
146 #elif defined(OS_WIN)
147 border_(NULL),
148 #endif 143 #endif
149 delegate_(NULL), 144 delegate_(NULL),
150 show_status_(kOpen), 145 show_status_(kOpen),
151 fade_away_on_close_(false), 146 fade_away_on_close_(false),
152 close_on_deactivate_(true), 147 close_on_deactivate_(true),
153 #if defined(TOOLKIT_USES_GTK) 148 #if defined(TOOLKIT_USES_GTK)
154 type_(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS), 149 type_(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS),
155 #endif 150 #endif
156 #if defined(OS_CHROMEOS) 151 #if defined(OS_CHROMEOS)
157 show_while_screen_is_locked_(false), 152 show_while_screen_is_locked_(false),
158 #endif 153 #endif
159 arrow_location_(views::BubbleBorder::NONE), 154 arrow_location_(views::BubbleBorder::NONE),
160 contents_(NULL), 155 contents_(NULL),
161 accelerator_registered_(false) { 156 accelerator_registered_(false) {
162 } 157 }
163 158
164 #if defined(OS_CHROMEOS) 159 #if defined(OS_CHROMEOS)
165 Bubble::Bubble(views::Widget::InitParams::Type type, 160 Bubble::Bubble(views::Widget::InitParams::Type type,
166 bool show_while_screen_is_locked) 161 bool show_while_screen_is_locked)
167 #if defined(USE_AURA) 162 #if defined(USE_AURA)
168 : views::NativeWidgetAura(new views::Widget), 163 : views::NativeWidgetAura(new views::Widget),
169 #elif defined(TOUCH_UI) 164 #elif defined(TOUCH_UI)
170 : views::NativeWidgetViews(new views::Widget), 165 : views::NativeWidgetViews(new views::Widget),
171 #else 166 #else
172 : views::NativeWidgetGtk(new views::Widget), 167 : views::NativeWidgetGtk(new views::Widget),
173 #endif 168 #endif
174 #if defined(TOOLKIT_USES_GTK)
175 border_contents_(NULL), 169 border_contents_(NULL),
176 #endif
177 delegate_(NULL), 170 delegate_(NULL),
178 show_status_(kOpen), 171 show_status_(kOpen),
179 fade_away_on_close_(false), 172 fade_away_on_close_(false),
180 #if defined(TOOLKIT_USES_GTK) 173 #if defined(TOOLKIT_USES_GTK)
181 type_(type), 174 type_(type),
182 #endif 175 #endif
183 show_while_screen_is_locked_(show_while_screen_is_locked), 176 show_while_screen_is_locked_(show_while_screen_is_locked),
184 arrow_location_(views::BubbleBorder::NONE), 177 arrow_location_(views::BubbleBorder::NONE),
185 contents_(NULL), 178 contents_(NULL),
186 accelerator_registered_(false) { 179 accelerator_registered_(false) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // (e.g. calling SetChecked() on checkboxes is safe). 266 // (e.g. calling SetChecked() on checkboxes is safe).
274 GetWidget()->SetContentsView(contents_view); 267 GetWidget()->SetContentsView(contents_view);
275 // Adding |contents| as a child has to be done before we call 268 // Adding |contents| as a child has to be done before we call
276 // contents->GetPreferredSize() below, since some supplied views don't 269 // contents->GetPreferredSize() below, since some supplied views don't
277 // actually initialize themselves until they're added to a hierarchy. 270 // actually initialize themselves until they're added to a hierarchy.
278 contents_view->AddChildView(contents); 271 contents_view->AddChildView(contents);
279 272
280 // Calculate and set the bounds for all windows and views. 273 // Calculate and set the bounds for all windows and views.
281 gfx::Rect window_bounds; 274 gfx::Rect window_bounds;
282 275
283 #if defined(USE_AURA) 276 #if defined(OS_WIN) && !defined(USE_AURA)
284 // TODO(beng):
285 NOTIMPLEMENTED();
286 #elif defined(OS_WIN)
287 // Initialize and position the border window. 277 // Initialize and position the border window.
288 window_bounds = border_->SizeAndGetBounds(position_relative_to, 278 window_bounds = border_->SizeAndGetBounds(position_relative_to,
289 arrow_location, 279 arrow_location,
290 contents->GetPreferredSize()); 280 contents->GetPreferredSize());
291 281
292 // Make |contents| take up the entire contents view. 282 // Make |contents| take up the entire contents view.
293 contents_view->SetLayoutManager(new views::FillLayout); 283 contents_view->SetLayoutManager(new views::FillLayout);
294 284
295 // Paint the background color behind the contents. 285 // Paint the background color behind the contents.
296 contents_view->set_background( 286 contents_view->set_background(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 accelerator_registered_ = false; 332 accelerator_registered_ = false;
343 } 333 }
344 334
345 BorderContents* Bubble::CreateBorderContents() { 335 BorderContents* Bubble::CreateBorderContents() {
346 return new BorderContents(); 336 return new BorderContents();
347 } 337 }
348 338
349 void Bubble::SizeToContents() { 339 void Bubble::SizeToContents() {
350 gfx::Rect window_bounds; 340 gfx::Rect window_bounds;
351 341
352 #if defined(USE_AURA) 342 #if defined(OS_WIN) && !defined(USE_AURA)
353 // TODO(beng):
354 NOTIMPLEMENTED();
355 #elif defined(OS_WIN)
356 // Initialize and position the border window. 343 // Initialize and position the border window.
357 window_bounds = border_->SizeAndGetBounds(position_relative_to_, 344 window_bounds = border_->SizeAndGetBounds(position_relative_to_,
358 arrow_location_, 345 arrow_location_,
359 contents_->GetPreferredSize()); 346 contents_->GetPreferredSize());
360 #else 347 #else
361 gfx::Rect contents_bounds; 348 gfx::Rect contents_bounds;
362 border_contents_->SizeAndGetBounds(position_relative_to_, 349 border_contents_->SizeAndGetBounds(position_relative_to_,
363 arrow_location_, false, contents_->GetPreferredSize(), 350 arrow_location_, false, contents_->GetPreferredSize(),
364 &contents_bounds, &window_bounds); 351 &contents_bounds, &window_bounds);
365 // |contents_view| has no layout manager, so we have to explicitly position 352 // |contents_view| has no layout manager, so we have to explicitly position
366 // its children. 353 // its children.
367 border_contents_->SetBoundsRect( 354 border_contents_->SetBoundsRect(
368 gfx::Rect(gfx::Point(), window_bounds.size())); 355 gfx::Rect(gfx::Point(), window_bounds.size()));
369 contents_->SetBoundsRect(contents_bounds); 356 contents_->SetBoundsRect(contents_bounds);
370 #endif 357 #endif
371 GetWidget()->SetBounds(window_bounds); 358 GetWidget()->SetBounds(window_bounds);
372 } 359 }
373 360
374 #if defined(USE_AURA) 361 #if defined(USE_AURA)
375 // TODO(beng): 362 void Bubble::OnLostActive() {
363 GetWidget()->Close();
364 }
376 #elif defined(OS_WIN) 365 #elif defined(OS_WIN)
377 void Bubble::OnActivate(UINT action, BOOL minimized, HWND window) { 366 void Bubble::OnActivate(UINT action, BOOL minimized, HWND window) {
378 // The popup should close when it is deactivated. 367 // The popup should close when it is deactivated.
379 if (action == WA_INACTIVE) { 368 if (action == WA_INACTIVE) {
380 if (close_on_deactivate_) 369 if (close_on_deactivate_)
381 GetWidget()->Close(); 370 GetWidget()->Close();
382 } else if (action == WA_ACTIVE) { 371 } else if (action == WA_ACTIVE) {
383 DCHECK(GetWidget()->GetRootView()->has_children()); 372 DCHECK(GetWidget()->GetRootView()->has_children());
384 GetWidget()->GetRootView()->child_at(0)->RequestFocus(); 373 GetWidget()->GetRootView()->child_at(0)->RequestFocus();
385 } 374 }
(...skipping 12 matching lines...) Expand all
398 void Bubble::DoClose(bool closed_by_escape) { 387 void Bubble::DoClose(bool closed_by_escape) {
399 if (show_status_ == kClosed) 388 if (show_status_ == kClosed)
400 return; 389 return;
401 390
402 if (accelerator_registered_) 391 if (accelerator_registered_)
403 UnregisterEscapeAccelerator(); 392 UnregisterEscapeAccelerator();
404 if (delegate_) 393 if (delegate_)
405 delegate_->BubbleClosing(this, closed_by_escape); 394 delegate_->BubbleClosing(this, closed_by_escape);
406 FOR_EACH_OBSERVER(Observer, observer_list_, OnBubbleClosing()); 395 FOR_EACH_OBSERVER(Observer, observer_list_, OnBubbleClosing());
407 show_status_ = kClosed; 396 show_status_ = kClosed;
408 #if defined(USE_AURA) 397 #if defined(OS_WIN) && !defined(USE_AURA)
409 // TODO(beng):
410 NOTIMPLEMENTED();
411 #elif defined(OS_WIN)
412 border_->Close(); 398 border_->Close();
413 #endif 399 #endif
414 #if defined(USE_AURA) 400 #if defined(USE_AURA)
415 // TODO(beng): 401 NativeWidgetAura::Close();
416 NOTIMPLEMENTED();
417 #elif defined(OS_WIN) 402 #elif defined(OS_WIN)
418 NativeWidgetWin::Close(); 403 NativeWidgetWin::Close();
419 #elif defined(TOUCH_UI) 404 #elif defined(TOUCH_UI)
420 NativeWidgetViews::Close(); 405 NativeWidgetViews::Close();
421 #elif defined(TOOLKIT_USES_GTK) 406 #elif defined(TOOLKIT_USES_GTK)
422 NativeWidgetGtk::Close(); 407 NativeWidgetGtk::Close();
423 #endif 408 #endif
424 } 409 }
425 410
426 void Bubble::FadeIn() { 411 void Bubble::FadeIn() {
(...skipping 28 matching lines...) Expand all
455 animation_->Hide(); 440 animation_->Hide();
456 } 441 }
457 442
458 bool Bubble::AcceleratorPressed(const views::Accelerator& accelerator) { 443 bool Bubble::AcceleratorPressed(const views::Accelerator& accelerator) {
459 if (!delegate_ || delegate_->CloseOnEscape()) { 444 if (!delegate_ || delegate_->CloseOnEscape()) {
460 DoClose(true); 445 DoClose(true);
461 return true; 446 return true;
462 } 447 }
463 return false; 448 return false;
464 } 449 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698