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

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

Issue 2897553002: Do not activate TrayBubbleView by default (Closed)
Patch Set: Add comment. 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 owned_bubble_border_(bubble_border_), 189 owned_bubble_border_(bubble_border_),
190 is_gesture_dragging_(false), 190 is_gesture_dragging_(false),
191 mouse_actively_entered_(false) { 191 mouse_actively_entered_(false) {
192 DCHECK(delegate_); 192 DCHECK(delegate_);
193 DCHECK(params_.parent_window); 193 DCHECK(params_.parent_window);
194 DCHECK(anchor_widget()); // Computed by BubbleDialogDelegateView(). 194 DCHECK(anchor_widget()); // Computed by BubbleDialogDelegateView().
195 bubble_border_->set_use_theme_background_color(!init_params.bg_color); 195 bubble_border_->set_use_theme_background_color(!init_params.bg_color);
196 bubble_border_->set_alignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); 196 bubble_border_->set_alignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
197 bubble_border_->set_paint_arrow(BubbleBorder::PAINT_NONE); 197 bubble_border_->set_paint_arrow(BubbleBorder::PAINT_NONE);
198 set_parent_window(params_.parent_window); 198 set_parent_window(params_.parent_window);
199 set_can_activate(params_.can_activate); 199 set_can_activate(false);
James Cook 2017/06/09 16:06:13 Is TrayBubbleView::InitParams::can_activate still
200 set_notify_enter_exit_on_child(true); 200 set_notify_enter_exit_on_child(true);
201 set_close_on_deactivate(init_params.close_on_deactivate); 201 set_close_on_deactivate(init_params.close_on_deactivate);
202 set_margins(gfx::Insets()); 202 set_margins(gfx::Insets());
203 SetPaintToLayer(); 203 SetPaintToLayer();
204 204
205 bubble_content_mask_.reset( 205 bubble_content_mask_.reset(
206 new TrayBubbleContentMask(bubble_border_->GetBorderCornerRadius())); 206 new TrayBubbleContentMask(bubble_border_->GetBorderCornerRadius()));
207 207
208 layout_->SetDefaultFlex(1); 208 layout_->SetDefaultFlex(1);
209 SetLayoutManager(layout_); 209 SetLayoutManager(layout_);
210 } 210 }
211 211
212 TrayBubbleView::~TrayBubbleView() { 212 TrayBubbleView::~TrayBubbleView() {
213 mouse_watcher_.reset(); 213 mouse_watcher_.reset();
214 // Inform host items (models) that their views are being destroyed. 214 if (delegate_) {
215 if (delegate_) 215 delegate_->UnregisterAllAccelerators(this);
216
217 // Inform host items (models) that their views are being destroyed.
216 delegate_->BubbleViewDestroyed(); 218 delegate_->BubbleViewDestroyed();
219 }
217 } 220 }
218 221
219 // static 222 // static
220 bool TrayBubbleView::IsATrayBubbleOpen() { 223 bool TrayBubbleView::IsATrayBubbleOpen() {
221 return g_current_tray_bubble_showing_count_ > 0; 224 return g_current_tray_bubble_showing_count_ > 0;
222 } 225 }
223 226
224 void TrayBubbleView::InitializeAndShowBubble() { 227 void TrayBubbleView::InitializeAndShowBubble() {
225 layer()->parent()->SetMaskLayer(bubble_content_mask_->layer()); 228 layer()->parent()->SetMaskLayer(bubble_content_mask_->layer());
226 229
227 GetWidget()->Show(); 230 GetWidget()->Show();
228 GetWidget()->GetNativeWindow()->SetEventTargeter( 231 GetWidget()->GetNativeWindow()->SetEventTargeter(
229 std::unique_ptr<ui::EventTargeter>(new BubbleWindowTargeter(this))); 232 std::unique_ptr<ui::EventTargeter>(new BubbleWindowTargeter(this)));
230 UpdateBubble(); 233 UpdateBubble();
231 234
232 ++g_current_tray_bubble_showing_count_; 235 ++g_current_tray_bubble_showing_count_;
236
237 // If TrayBubbleView cannot be activated, register accelerators to activate
James Cook 2017/06/09 16:06:13 Comment says "activate it" but list contains Escap
yawano 2017/06/12 09:11:04 Done.
238 // it by keyboard.
239 if (delegate_ && !CanActivate()) {
240 delegate_->RegisterAccelerators(
241 {ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE),
242 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE),
243 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN)},
244 this);
245 }
233 } 246 }
234 247
235 void TrayBubbleView::UpdateBubble() { 248 void TrayBubbleView::UpdateBubble() {
236 if (GetWidget()) { 249 if (GetWidget()) {
237 SizeToContents(); 250 SizeToContents();
238 bubble_content_mask_->layer()->SetBounds(layer()->bounds()); 251 bubble_content_mask_->layer()->SetBounds(layer()->bounds());
239 GetWidget()->GetRootView()->SchedulePaint(); 252 GetWidget()->GetRootView()->SchedulePaint();
253
254 // When extra keyboard accessibility is enabled, focus the default item if
255 // no item is focused.
256 if (delegate_ && delegate_->ShouldEnableExtraKeyboardAccessibility())
257 FocusDefaultIfNeeded();
240 } 258 }
241 } 259 }
242 260
243 void TrayBubbleView::SetMaxHeight(int height) { 261 void TrayBubbleView::SetMaxHeight(int height) {
244 params_.max_height = height; 262 params_.max_height = height;
245 if (GetWidget()) 263 if (GetWidget())
246 SizeToContents(); 264 SizeToContents();
247 } 265 }
248 266
249 void TrayBubbleView::SetBottomPadding(int padding) { 267 void TrayBubbleView::SetBottomPadding(int padding) {
250 layout_->set_inside_border_insets(gfx::Insets(0, 0, padding, 0)); 268 layout_->set_inside_border_insets(gfx::Insets(0, 0, padding, 0));
251 } 269 }
252 270
253 void TrayBubbleView::SetWidth(int width) { 271 void TrayBubbleView::SetWidth(int width) {
254 width = std::max(std::min(width, params_.max_width), params_.min_width); 272 width = std::max(std::min(width, params_.max_width), params_.min_width);
255 if (preferred_width_ == width) 273 if (preferred_width_ == width)
256 return; 274 return;
257 preferred_width_ = width; 275 preferred_width_ = width;
258 if (GetWidget()) 276 if (GetWidget())
259 SizeToContents(); 277 SizeToContents();
260 } 278 }
261 279
262 gfx::Insets TrayBubbleView::GetBorderInsets() const { 280 gfx::Insets TrayBubbleView::GetBorderInsets() const {
263 return bubble_border_->GetInsets(); 281 return bubble_border_->GetInsets();
264 } 282 }
265 283
284 void TrayBubbleView::ResetDelegate() {
285 if (delegate_)
286 delegate_->UnregisterAllAccelerators(this);
287
288 delegate_ = nullptr;
289 }
290
266 int TrayBubbleView::GetDialogButtons() const { 291 int TrayBubbleView::GetDialogButtons() const {
267 return ui::DIALOG_BUTTON_NONE; 292 return ui::DIALOG_BUTTON_NONE;
268 } 293 }
269 294
270 void TrayBubbleView::OnBeforeBubbleWidgetInit(Widget::InitParams* params, 295 void TrayBubbleView::OnBeforeBubbleWidgetInit(Widget::InitParams* params,
271 Widget* bubble_widget) const { 296 Widget* bubble_widget) const {
272 // Apply a WM-provided shadow (see ui/wm/core/). 297 // Apply a WM-provided shadow (see ui/wm/core/).
273 params->shadow_type = Widget::InitParams::SHADOW_TYPE_DROP; 298 params->shadow_type = Widget::InitParams::SHADOW_TYPE_DROP;
274 params->shadow_elevation = wm::ShadowElevation::LARGE; 299 params->shadow_elevation = wm::ShadowElevation::LARGE;
275 } 300 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 391
367 void TrayBubbleView::MouseMovedOutOfHost() { 392 void TrayBubbleView::MouseMovedOutOfHost() {
368 // The mouse was accidentally over the bubble when it opened and the AutoClose 393 // The mouse was accidentally over the bubble when it opened and the AutoClose
369 // logic was not activated. Now that the user did move the mouse we tell the 394 // logic was not activated. Now that the user did move the mouse we tell the
370 // delegate to disable AutoClose. 395 // delegate to disable AutoClose.
371 delegate_->OnMouseEnteredView(); 396 delegate_->OnMouseEnteredView();
372 mouse_actively_entered_ = true; 397 mouse_actively_entered_ = true;
373 mouse_watcher_->Stop(); 398 mouse_watcher_->Stop();
374 } 399 }
375 400
401 bool TrayBubbleView::AcceleratorPressed(const ui::Accelerator& accelerator) {
402 if (accelerator == ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)) {
403 CloseBubbleView();
404 return true;
405 } else if (accelerator == ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE) ||
James Cook 2017/06/09 16:06:13 nit: no "else" after return
yawano 2017/06/12 09:11:04 Done.
406 accelerator == ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN)) {
407 ui::KeyEvent key_event(
408 accelerator.key_state() == ui::Accelerator::KeyState::PRESSED
409 ? ui::EventType::ET_KEY_PRESSED
410 : ui::EventType::ET_KEY_RELEASED,
411 accelerator.key_code(), accelerator.modifiers());
412 ActivateAndStartNavigation(key_event);
413 return true;
414 }
415
416 return false;
417 }
418
376 void TrayBubbleView::ChildPreferredSizeChanged(View* child) { 419 void TrayBubbleView::ChildPreferredSizeChanged(View* child) {
377 SizeToContents(); 420 SizeToContents();
378 } 421 }
379 422
380 void TrayBubbleView::ViewHierarchyChanged( 423 void TrayBubbleView::ViewHierarchyChanged(
381 const ViewHierarchyChangedDetails& details) { 424 const ViewHierarchyChangedDetails& details) {
382 if (details.is_add && details.child == this) { 425 if (details.is_add && details.child == this) {
383 details.parent->SetPaintToLayer(); 426 details.parent->SetPaintToLayer();
384 details.parent->layer()->SetMasksToBounds(true); 427 details.parent->layer()->SetMasksToBounds(true);
385 } 428 }
386 } 429 }
387 430
431 void TrayBubbleView::CloseBubbleView() {
432 if (!delegate_)
433 return;
434
435 delegate_->UnregisterAllAccelerators(this);
436 delegate_->HideBubble(this);
437 }
438
439 void TrayBubbleView::ActivateAndStartNavigation(const ui::KeyEvent& key_event) {
440 set_can_activate(true);
441 GetWidget()->Activate();
442 if (!GetWidget()->GetFocusManager()->OnKeyEvent(key_event) && delegate_) {
443 // No need to handle accelerators by TrayBubbleView after focus has moved to
444 // the widget. The focused view will handle focus traversal.
445 // FocusManager::OnKeyEvent returns false when it consumes a key event.
446 delegate_->UnregisterAllAccelerators(this);
447 }
448 }
449
450 void TrayBubbleView::FocusDefaultIfNeeded() {
451 views::FocusManager* manager = GetFocusManager();
452 if (!manager || manager->GetFocusedView())
453 return;
454
455 views::View* view =
456 manager->GetNextFocusableView(nullptr, nullptr, false, false);
457 if (!view)
458 return;
459
460 set_can_activate(true);
461 GetWidget()->Activate();
462
463 view->RequestFocus();
464 }
465
388 } // namespace views 466 } // namespace views
OLDNEW
« ash/system/web_notification/web_notification_tray.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