| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/system/palette/palette_tray.h" | 5 #include "ash/system/palette/palette_tray.h" |
| 6 | 6 |
| 7 #include "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
| 8 #include "ash/accessibility_delegate.h" | 8 #include "ash/accessibility_delegate.h" |
| 9 #include "ash/resources/vector_icons/vector_icons.h" | 9 #include "ash/resources/vector_icons/vector_icons.h" |
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 156 } |
| 157 | 157 |
| 158 PaletteTray::~PaletteTray() { | 158 PaletteTray::~PaletteTray() { |
| 159 if (bubble_) | 159 if (bubble_) |
| 160 bubble_->bubble_view()->ResetDelegate(); | 160 bubble_->bubble_view()->ResetDelegate(); |
| 161 | 161 |
| 162 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); | 162 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); |
| 163 Shell::Get()->RemoveShellObserver(this); | 163 Shell::Get()->RemoveShellObserver(this); |
| 164 } | 164 } |
| 165 | 165 |
| 166 bool PaletteTray::PerformAction(const ui::Event& event) { | |
| 167 if (bubble_) { | |
| 168 if (num_actions_in_bubble_ == 0) | |
| 169 RecordPaletteOptionsUsage(PaletteTrayOptions::PALETTE_CLOSED_NO_ACTION); | |
| 170 HidePalette(); | |
| 171 return true; | |
| 172 } | |
| 173 | |
| 174 return ShowPalette(); | |
| 175 } | |
| 176 | |
| 177 bool PaletteTray::ShowPalette() { | 166 bool PaletteTray::ShowPalette() { |
| 178 if (bubble_) | 167 if (bubble_) |
| 179 return false; | 168 return false; |
| 180 | 169 |
| 181 DCHECK(tray_container()); | 170 DCHECK(tray_container()); |
| 182 | 171 |
| 183 views::TrayBubbleView::InitParams init_params; | 172 views::TrayBubbleView::InitParams init_params; |
| 184 init_params.delegate = this; | 173 init_params.delegate = this; |
| 185 init_params.parent_window = GetBubbleWindowContainer(); | 174 init_params.parent_window = GetBubbleWindowContainer(); |
| 186 init_params.anchor_view = GetBubbleAnchor(); | 175 init_params.anchor_view = GetBubbleAnchor(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 } | 306 } |
| 318 | 307 |
| 319 bool PaletteTray::ShouldEnableExtraKeyboardAccessibility() { | 308 bool PaletteTray::ShouldEnableExtraKeyboardAccessibility() { |
| 320 return Shell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled(); | 309 return Shell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled(); |
| 321 } | 310 } |
| 322 | 311 |
| 323 void PaletteTray::HideBubble(const views::TrayBubbleView* bubble_view) { | 312 void PaletteTray::HideBubble(const views::TrayBubbleView* bubble_view) { |
| 324 HideBubbleWithView(bubble_view); | 313 HideBubbleWithView(bubble_view); |
| 325 } | 314 } |
| 326 | 315 |
| 316 bool PaletteTray::ProcessGestureEventForBubble(ui::GestureEvent* event) { |
| 317 return drag_controller()->ProcessGestureEvent(*event, this, |
| 318 true /* is_on_bubble */); |
| 319 } |
| 320 |
| 327 void PaletteTray::HidePalette() { | 321 void PaletteTray::HidePalette() { |
| 328 is_bubble_auto_opened_ = false; | 322 is_bubble_auto_opened_ = false; |
| 329 num_actions_in_bubble_ = 0; | 323 num_actions_in_bubble_ = 0; |
| 330 bubble_.reset(); | 324 bubble_.reset(); |
| 331 | 325 |
| 332 shelf()->UpdateAutoHideState(); | 326 shelf()->UpdateAutoHideState(); |
| 333 } | 327 } |
| 334 | 328 |
| 335 void PaletteTray::HidePaletteImmediately() { | 329 void PaletteTray::HidePaletteImmediately() { |
| 336 if (bubble_) | 330 if (bubble_) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 // |delegate| can be null in tests. | 372 // |delegate| can be null in tests. |
| 379 if (!delegate) | 373 if (!delegate) |
| 380 return; | 374 return; |
| 381 | 375 |
| 382 // OnPaletteEnabledPrefChanged will get called with the initial pref value, | 376 // OnPaletteEnabledPrefChanged will get called with the initial pref value, |
| 383 // which will take care of showing the palette. | 377 // which will take care of showing the palette. |
| 384 palette_enabled_subscription_ = delegate->AddPaletteEnableListener(base::Bind( | 378 palette_enabled_subscription_ = delegate->AddPaletteEnableListener(base::Bind( |
| 385 &PaletteTray::OnPaletteEnabledPrefChanged, weak_factory_.GetWeakPtr())); | 379 &PaletteTray::OnPaletteEnabledPrefChanged, weak_factory_.GetWeakPtr())); |
| 386 } | 380 } |
| 387 | 381 |
| 382 bool PaletteTray::PerformAction(const ui::Event& event) { |
| 383 if (bubble_) { |
| 384 if (num_actions_in_bubble_ == 0) |
| 385 RecordPaletteOptionsUsage(PaletteTrayOptions::PALETTE_CLOSED_NO_ACTION); |
| 386 HidePalette(); |
| 387 return true; |
| 388 } |
| 389 |
| 390 return ShowPalette(); |
| 391 } |
| 392 |
| 393 bool PaletteTray::HasBubble() { |
| 394 return bubble_.get() != NULL; |
| 395 } |
| 396 |
| 397 void PaletteTray::CloseBubble() { |
| 398 HidePalette(); |
| 399 } |
| 400 |
| 401 void PaletteTray::ShowBubble() { |
| 402 ShowPalette(); |
| 403 } |
| 404 |
| 405 views::TrayBubbleView* PaletteTray::GetBubbleView() { |
| 406 if (HasBubble()) |
| 407 return bubble_->bubble_view(); |
| 408 return nullptr; |
| 409 } |
| 410 |
| 411 void PaletteTray::OnGestureEvent(ui::GestureEvent* event) { |
| 412 if (drag_controller()->ProcessGestureEvent(*event, this, |
| 413 false /* is_on_bubble */)) { |
| 414 event->SetHandled(); |
| 415 } else { |
| 416 TrayBackgroundView::OnGestureEvent(event); |
| 417 } |
| 418 } |
| 419 |
| 388 void PaletteTray::UpdateTrayIcon() { | 420 void PaletteTray::UpdateTrayIcon() { |
| 389 icon_->SetImage(CreateVectorIcon( | 421 icon_->SetImage(CreateVectorIcon( |
| 390 palette_tool_manager_->GetActiveTrayIcon( | 422 palette_tool_manager_->GetActiveTrayIcon( |
| 391 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)), | 423 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)), |
| 392 kTrayIconSize, kShelfIconColor)); | 424 kTrayIconSize, kShelfIconColor)); |
| 393 } | 425 } |
| 394 | 426 |
| 395 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { | 427 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { |
| 396 is_palette_enabled_ = enabled; | 428 is_palette_enabled_ = enabled; |
| 397 | 429 |
| 398 if (!enabled) { | 430 if (!enabled) { |
| 399 SetVisible(false); | 431 SetVisible(false); |
| 400 palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE); | 432 palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE); |
| 401 } else { | 433 } else { |
| 402 UpdateIconVisibility(); | 434 UpdateIconVisibility(); |
| 403 } | 435 } |
| 404 } | 436 } |
| 405 | 437 |
| 406 void PaletteTray::UpdateIconVisibility() { | 438 void PaletteTray::UpdateIconVisibility() { |
| 407 SetVisible(is_palette_enabled_ && palette_utils::HasStylusInput() && | 439 SetVisible(is_palette_enabled_ && palette_utils::HasStylusInput() && |
| 408 ShouldShowOnDisplay(this) && IsInUserSession()); | 440 ShouldShowOnDisplay(this) && IsInUserSession()); |
| 409 } | 441 } |
| 410 | 442 |
| 411 } // namespace ash | 443 } // namespace ash |
| OLD | NEW |