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

Side by Side Diff: ui/views/bubble/tray_bubble_view.cc

Issue 2958693002: Reland with a fix: Do not activate TrayBubbleView by default (Closed)
Patch Set: Add a fix. Created 3 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/bubble/tray_bubble_view.h" 5 #include "ui/views/bubble/tray_bubble_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "cc/paint/paint_flags.h" 10 #include "cc/paint/paint_flags.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 owned_bubble_border_(bubble_border_), 187 owned_bubble_border_(bubble_border_),
188 is_gesture_dragging_(false), 188 is_gesture_dragging_(false),
189 mouse_actively_entered_(false) { 189 mouse_actively_entered_(false) {
190 DCHECK(delegate_); 190 DCHECK(delegate_);
191 DCHECK(params_.parent_window); 191 DCHECK(params_.parent_window);
192 DCHECK(anchor_widget()); // Computed by BubbleDialogDelegateView(). 192 DCHECK(anchor_widget()); // Computed by BubbleDialogDelegateView().
193 bubble_border_->set_use_theme_background_color(!init_params.bg_color); 193 bubble_border_->set_use_theme_background_color(!init_params.bg_color);
194 bubble_border_->set_alignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); 194 bubble_border_->set_alignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
195 bubble_border_->set_paint_arrow(BubbleBorder::PAINT_NONE); 195 bubble_border_->set_paint_arrow(BubbleBorder::PAINT_NONE);
196 set_parent_window(params_.parent_window); 196 set_parent_window(params_.parent_window);
197 set_can_activate(params_.can_activate); 197 set_can_activate(false);
198 set_notify_enter_exit_on_child(true); 198 set_notify_enter_exit_on_child(true);
199 set_close_on_deactivate(init_params.close_on_deactivate); 199 set_close_on_deactivate(init_params.close_on_deactivate);
200 set_margins(gfx::Insets()); 200 set_margins(gfx::Insets());
201 SetPaintToLayer(); 201 SetPaintToLayer();
202 202
203 bubble_content_mask_.reset( 203 bubble_content_mask_.reset(
204 new TrayBubbleContentMask(bubble_border_->GetBorderCornerRadius())); 204 new TrayBubbleContentMask(bubble_border_->GetBorderCornerRadius()));
205 205
206 layout_->SetDefaultFlex(1); 206 layout_->SetDefaultFlex(1);
207 SetLayoutManager(layout_); 207 SetLayoutManager(layout_);
208 } 208 }
209 209
210 TrayBubbleView::~TrayBubbleView() { 210 TrayBubbleView::~TrayBubbleView() {
211 mouse_watcher_.reset(); 211 mouse_watcher_.reset();
212 // Inform host items (models) that their views are being destroyed. 212 if (delegate_) {
213 if (delegate_) 213 delegate_->UnregisterAllAccelerators(this);
214
215 // Inform host items (models) that their views are being destroyed.
214 delegate_->BubbleViewDestroyed(); 216 delegate_->BubbleViewDestroyed();
217 }
215 } 218 }
216 219
217 // static 220 // static
218 bool TrayBubbleView::IsATrayBubbleOpen() { 221 bool TrayBubbleView::IsATrayBubbleOpen() {
219 return g_current_tray_bubble_showing_count_ > 0; 222 return g_current_tray_bubble_showing_count_ > 0;
220 } 223 }
221 224
222 void TrayBubbleView::InitializeAndShowBubble() { 225 void TrayBubbleView::InitializeAndShowBubble() {
223 layer()->parent()->SetMaskLayer(bubble_content_mask_->layer()); 226 layer()->parent()->SetMaskLayer(bubble_content_mask_->layer());
224 227
225 GetWidget()->Show(); 228 GetWidget()->Show();
226 GetWidget()->GetNativeWindow()->SetEventTargeter( 229 GetWidget()->GetNativeWindow()->SetEventTargeter(
227 std::unique_ptr<ui::EventTargeter>(new BubbleWindowTargeter(this))); 230 std::unique_ptr<ui::EventTargeter>(new BubbleWindowTargeter(this)));
228 UpdateBubble(); 231 UpdateBubble();
229 232
230 ++g_current_tray_bubble_showing_count_; 233 ++g_current_tray_bubble_showing_count_;
234
235 // If TrayBubbleView cannot be activated, register accelerators to capture key
236 // events for activating the view or closing it. TrayBubbleView expects that
237 // those accelerators are registered at the global level.
238 if (delegate_ && !CanActivate()) {
239 delegate_->RegisterAccelerators(
240 {ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE),
241 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE),
242 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN)},
243 this);
244 }
231 } 245 }
232 246
233 void TrayBubbleView::UpdateBubble() { 247 void TrayBubbleView::UpdateBubble() {
234 if (GetWidget()) { 248 if (GetWidget()) {
235 SizeToContents(); 249 SizeToContents();
236 bubble_content_mask_->layer()->SetBounds(layer()->bounds()); 250 bubble_content_mask_->layer()->SetBounds(layer()->bounds());
237 GetWidget()->GetRootView()->SchedulePaint(); 251 GetWidget()->GetRootView()->SchedulePaint();
252
253 // When extra keyboard accessibility is enabled, focus the default item if
254 // no item is focused.
255 if (delegate_ && delegate_->ShouldEnableExtraKeyboardAccessibility())
256 FocusDefaultIfNeeded();
238 } 257 }
239 } 258 }
240 259
241 void TrayBubbleView::SetMaxHeight(int height) { 260 void TrayBubbleView::SetMaxHeight(int height) {
242 params_.max_height = height; 261 params_.max_height = height;
243 if (GetWidget()) 262 if (GetWidget())
244 SizeToContents(); 263 SizeToContents();
245 } 264 }
246 265
247 void TrayBubbleView::SetBottomPadding(int padding) { 266 void TrayBubbleView::SetBottomPadding(int padding) {
248 layout_->set_inside_border_insets(gfx::Insets(0, 0, padding, 0)); 267 layout_->set_inside_border_insets(gfx::Insets(0, 0, padding, 0));
249 } 268 }
250 269
251 void TrayBubbleView::SetWidth(int width) { 270 void TrayBubbleView::SetWidth(int width) {
252 width = std::max(std::min(width, params_.max_width), params_.min_width); 271 width = std::max(std::min(width, params_.max_width), params_.min_width);
253 if (preferred_width_ == width) 272 if (preferred_width_ == width)
254 return; 273 return;
255 preferred_width_ = width; 274 preferred_width_ = width;
256 if (GetWidget()) 275 if (GetWidget())
257 SizeToContents(); 276 SizeToContents();
258 } 277 }
259 278
260 gfx::Insets TrayBubbleView::GetBorderInsets() const { 279 gfx::Insets TrayBubbleView::GetBorderInsets() const {
261 return bubble_border_->GetInsets(); 280 return bubble_border_->GetInsets();
262 } 281 }
263 282
283 void TrayBubbleView::ResetDelegate() {
284 if (delegate_)
285 delegate_->UnregisterAllAccelerators(this);
286
287 delegate_ = nullptr;
288 }
289
264 int TrayBubbleView::GetDialogButtons() const { 290 int TrayBubbleView::GetDialogButtons() const {
265 return ui::DIALOG_BUTTON_NONE; 291 return ui::DIALOG_BUTTON_NONE;
266 } 292 }
267 293
268 void TrayBubbleView::SizeToContents() { 294 void TrayBubbleView::SizeToContents() {
269 BubbleDialogDelegateView::SizeToContents(); 295 BubbleDialogDelegateView::SizeToContents();
270 bubble_content_mask_->layer()->SetBounds(layer()->bounds()); 296 bubble_content_mask_->layer()->SetBounds(layer()->bounds());
271 } 297 }
272 298
273 void TrayBubbleView::OnBeforeBubbleWidgetInit(Widget::InitParams* params, 299 void TrayBubbleView::OnBeforeBubbleWidgetInit(Widget::InitParams* params,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 395
370 void TrayBubbleView::MouseMovedOutOfHost() { 396 void TrayBubbleView::MouseMovedOutOfHost() {
371 // The mouse was accidentally over the bubble when it opened and the AutoClose 397 // The mouse was accidentally over the bubble when it opened and the AutoClose
372 // logic was not activated. Now that the user did move the mouse we tell the 398 // logic was not activated. Now that the user did move the mouse we tell the
373 // delegate to disable AutoClose. 399 // delegate to disable AutoClose.
374 delegate_->OnMouseEnteredView(); 400 delegate_->OnMouseEnteredView();
375 mouse_actively_entered_ = true; 401 mouse_actively_entered_ = true;
376 mouse_watcher_->Stop(); 402 mouse_watcher_->Stop();
377 } 403 }
378 404
405 bool TrayBubbleView::AcceleratorPressed(const ui::Accelerator& accelerator) {
406 if (accelerator == ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)) {
407 CloseBubbleView();
408 return true;
409 }
410
411 if (accelerator == ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE) ||
412 accelerator == ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN)) {
413 ui::KeyEvent key_event(
414 accelerator.key_state() == ui::Accelerator::KeyState::PRESSED
415 ? ui::EventType::ET_KEY_PRESSED
416 : ui::EventType::ET_KEY_RELEASED,
417 accelerator.key_code(), accelerator.modifiers());
418 ActivateAndStartNavigation(key_event);
419 return true;
420 }
421
422 return false;
423 }
424
379 void TrayBubbleView::ChildPreferredSizeChanged(View* child) { 425 void TrayBubbleView::ChildPreferredSizeChanged(View* child) {
380 SizeToContents(); 426 SizeToContents();
381 } 427 }
382 428
383 void TrayBubbleView::ViewHierarchyChanged( 429 void TrayBubbleView::ViewHierarchyChanged(
384 const ViewHierarchyChangedDetails& details) { 430 const ViewHierarchyChangedDetails& details) {
385 if (details.is_add && details.child == this) { 431 if (details.is_add && details.child == this) {
386 details.parent->SetPaintToLayer(); 432 details.parent->SetPaintToLayer();
387 details.parent->layer()->SetMasksToBounds(true); 433 details.parent->layer()->SetMasksToBounds(true);
388 } 434 }
389 } 435 }
390 436
437 void TrayBubbleView::CloseBubbleView() {
438 if (!delegate_)
439 return;
440
441 delegate_->UnregisterAllAccelerators(this);
442 delegate_->HideBubble(this);
443 }
444
445 void TrayBubbleView::ActivateAndStartNavigation(const ui::KeyEvent& key_event) {
446 // No need to explicitly activate the widget. FocusManager will activate it if
447 // necessary.
448 set_can_activate(true);
449
450 if (!GetWidget()->GetFocusManager()->OnKeyEvent(key_event) && delegate_) {
451 // No need to handle accelerators by TrayBubbleView after focus has moved to
452 // the widget. The focused view will handle focus traversal.
453 // FocusManager::OnKeyEvent returns false when it consumes a key event.
454 delegate_->UnregisterAllAccelerators(this);
455 }
456 }
457
458 void TrayBubbleView::FocusDefaultIfNeeded() {
459 views::FocusManager* manager = GetFocusManager();
460 if (!manager || manager->GetFocusedView())
461 return;
462
463 views::View* view =
464 manager->GetNextFocusableView(nullptr, nullptr, false, false);
465 if (!view)
466 return;
467
468 // No need to explicitly activate the widget. View::RequestFocus will activate
469 // it if necessary.
470 set_can_activate(true);
471
472 view->RequestFocus();
473 }
474
391 } // namespace views 475 } // namespace views
OLDNEW
« ash/system/tray/system_tray_bubble.cc ('K') | « ui/views/bubble/tray_bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698