Chromium Code Reviews| 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/common/system/chromeos/palette/palette_tray.h" | 5 #include "ash/common/system/chromeos/palette/palette_tray.h" |
| 6 | 6 |
| 7 #include "ash/common/shelf/shelf_constants.h" | 7 #include "ash/common/shelf/shelf_constants.h" |
| 8 #include "ash/common/shelf/wm_shelf.h" | 8 #include "ash/common/shelf/wm_shelf.h" |
| 9 #include "ash/common/shelf/wm_shelf_util.h" | 9 #include "ash/common/shelf/wm_shelf_util.h" |
| 10 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
| 11 #include "ash/common/system/chromeos/palette/palette_tool_manager.h" | 11 #include "ash/common/system/chromeos/palette/palette_tool_manager.h" |
| 12 #include "ash/common/system/chromeos/palette/palette_utils.h" | 12 #include "ash/common/system/chromeos/palette/palette_utils.h" |
| 13 #include "ash/common/system/tray/system_tray_delegate.h" | 13 #include "ash/common/system/tray/system_tray_delegate.h" |
| 14 #include "ash/common/system/tray/tray_bubble_wrapper.h" | 14 #include "ash/common/system/tray/tray_bubble_wrapper.h" |
| 15 #include "ash/common/system/tray/tray_constants.h" | 15 #include "ash/common/system/tray/tray_constants.h" |
| 16 #include "ash/common/system/tray/tray_popup_header_button.h" | 16 #include "ash/common/system/tray/tray_popup_header_button.h" |
| 17 #include "ash/common/wm_lookup.h" | 17 #include "ash/common/wm_lookup.h" |
| 18 #include "ash/common/wm_root_window_controller.h" | 18 #include "ash/common/wm_root_window_controller.h" |
| 19 #include "ash/common/wm_shell.h" | 19 #include "ash/common/wm_shell.h" |
| 20 #include "ash/common/wm_window.h" | 20 #include "ash/common/wm_window.h" |
| 21 #include "base/metrics/histogram.h" | |
|
Ilya Sherman
2016/09/02 21:39:30
nit: histogram_macros
xiaoyinh(OOO Sep 11-29)
2016/09/06 17:40:05
Done.
| |
| 21 #include "grit/ash_resources.h" | 22 #include "grit/ash_resources.h" |
| 22 #include "grit/ash_strings.h" | 23 #include "grit/ash_strings.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/events/devices/stylus_state.h" | 26 #include "ui/events/devices/stylus_state.h" |
| 26 #include "ui/gfx/color_palette.h" | 27 #include "ui/gfx/color_palette.h" |
| 27 #include "ui/gfx/paint_vector_icon.h" | 28 #include "ui/gfx/paint_vector_icon.h" |
| 28 #include "ui/gfx/vector_icons_public.h" | 29 #include "ui/gfx/vector_icons_public.h" |
| 29 #include "ui/views/controls/image_view.h" | 30 #include "ui/views/controls/image_view.h" |
| 30 #include "ui/views/controls/label.h" | 31 #include "ui/views/controls/label.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SETTINGS)); | 102 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SETTINGS)); |
| 102 AddChildView(settings_button_); | 103 AddChildView(settings_button_); |
| 103 } | 104 } |
| 104 | 105 |
| 105 ~TitleView() override {} | 106 ~TitleView() override {} |
| 106 | 107 |
| 107 private: | 108 private: |
| 108 // views::ButtonListener: | 109 // views::ButtonListener: |
| 109 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 110 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
| 110 if (sender == settings_button_) { | 111 if (sender == settings_button_) { |
| 112 palette_tray_->RecordPaletteMetrics( | |
| 113 ash::PaletteTrayOptions::PALETTE_SETTINGS_BUTTON); | |
| 111 WmShell::Get()->system_tray_delegate()->ShowPaletteSettings(); | 114 WmShell::Get()->system_tray_delegate()->ShowPaletteSettings(); |
|
jdufault
2016/09/02 21:54:30
ShowPaletteSettings should already be recording a
xiaoyinh(OOO Sep 11-29)
2016/09/06 17:40:05
Should I remove mine if that's case? It might stil
| |
| 112 palette_tray_->HidePalette(); | 115 palette_tray_->HidePalette(); |
| 113 } else if (sender == help_button_) { | 116 } else if (sender == help_button_) { |
| 117 palette_tray_->RecordPaletteMetrics( | |
| 118 ash::PaletteTrayOptions::PALETTE_HELP_BUTTON); | |
| 114 WmShell::Get()->system_tray_delegate()->ShowPaletteHelp(); | 119 WmShell::Get()->system_tray_delegate()->ShowPaletteHelp(); |
| 115 palette_tray_->HidePalette(); | 120 palette_tray_->HidePalette(); |
| 116 } else { | 121 } else { |
| 117 NOTREACHED(); | 122 NOTREACHED(); |
| 118 } | 123 } |
| 119 } | 124 } |
| 120 | 125 |
| 121 // Unowned pointers to button views so we can determine which button was | 126 // Unowned pointers to button views so we can determine which button was |
| 122 // clicked. | 127 // clicked. |
| 123 ash::TrayPopupHeaderButton* settings_button_; | 128 ash::TrayPopupHeaderButton* settings_button_; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 PaletteTray::~PaletteTray() { | 171 PaletteTray::~PaletteTray() { |
| 167 if (bubble_) | 172 if (bubble_) |
| 168 bubble_->bubble_view()->reset_delegate(); | 173 bubble_->bubble_view()->reset_delegate(); |
| 169 | 174 |
| 170 WmShell::Get()->RemoveShellObserver(this); | 175 WmShell::Get()->RemoveShellObserver(this); |
| 171 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this); | 176 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this); |
| 172 } | 177 } |
| 173 | 178 |
| 174 bool PaletteTray::PerformAction(const ui::Event& event) { | 179 bool PaletteTray::PerformAction(const ui::Event& event) { |
| 175 if (bubble_) { | 180 if (bubble_) { |
| 176 bubble_.reset(); | 181 if (num_actions_in_palette == 0) { |
| 182 RecordPaletteMetrics(ash::PaletteTrayOptions::PALETTE_CLOSED_NO_ACTION); | |
| 183 } | |
| 184 HidePalette(); | |
| 177 return true; | 185 return true; |
| 178 } | 186 } |
| 179 | 187 |
| 180 return ShowPalette(); | 188 return ShowPalette(); |
| 181 } | 189 } |
| 182 | 190 |
| 183 bool PaletteTray::ShowPalette() { | 191 bool PaletteTray::ShowPalette() { |
| 184 if (bubble_) | 192 if (bubble_) |
| 185 return false; | 193 return false; |
| 186 | 194 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 void PaletteTray::SessionStateChanged( | 237 void PaletteTray::SessionStateChanged( |
| 230 SessionStateDelegate::SessionState state) { | 238 SessionStateDelegate::SessionState state) { |
| 231 UpdateIconVisibility(); | 239 UpdateIconVisibility(); |
| 232 } | 240 } |
| 233 | 241 |
| 234 void PaletteTray::OnLockStateChanged(bool locked) { | 242 void PaletteTray::OnLockStateChanged(bool locked) { |
| 235 UpdateIconVisibility(); | 243 UpdateIconVisibility(); |
| 236 } | 244 } |
| 237 | 245 |
| 238 void PaletteTray::ClickedOutsideBubble() { | 246 void PaletteTray::ClickedOutsideBubble() { |
| 239 bubble_.reset(); | 247 if (num_actions_in_palette == 0) |
| 248 RecordPaletteMetrics(ash::PaletteTrayOptions::PALETTE_CLOSED_NO_ACTION); | |
| 249 HidePalette(); | |
| 240 } | 250 } |
| 241 | 251 |
| 242 base::string16 PaletteTray::GetAccessibleNameForTray() { | 252 base::string16 PaletteTray::GetAccessibleNameForTray() { |
| 243 return l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_TITLE); | 253 return l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_TITLE); |
| 244 } | 254 } |
| 245 | 255 |
| 246 void PaletteTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { | 256 void PaletteTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { |
| 247 if (bubble_->bubble_view() == bubble_view) | 257 if (bubble_->bubble_view() == bubble_view) |
| 248 bubble_.reset(); | 258 HidePalette(); |
| 249 } | 259 } |
| 250 | 260 |
| 251 void PaletteTray::BubbleViewDestroyed() { | 261 void PaletteTray::BubbleViewDestroyed() { |
| 252 palette_tool_manager_->NotifyViewsDestroyed(); | 262 palette_tool_manager_->NotifyViewsDestroyed(); |
| 253 SetDrawBackgroundAsActive(false); | 263 SetDrawBackgroundAsActive(false); |
| 254 } | 264 } |
| 255 | 265 |
| 256 void PaletteTray::OnMouseEnteredView() {} | 266 void PaletteTray::OnMouseEnteredView() {} |
| 257 | 267 |
| 258 void PaletteTray::OnMouseExitedView() {} | 268 void PaletteTray::OnMouseExitedView() {} |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 ->GetRootWindowController() | 306 ->GetRootWindowController() |
| 297 ->ConfigureWidgetInitParamsForContainer( | 307 ->ConfigureWidgetInitParamsForContainer( |
| 298 bubble_widget, kShellWindowId_SettingBubbleContainer, params); | 308 bubble_widget, kShellWindowId_SettingBubbleContainer, params); |
| 299 } | 309 } |
| 300 | 310 |
| 301 void PaletteTray::HideBubble(const views::TrayBubbleView* bubble_view) { | 311 void PaletteTray::HideBubble(const views::TrayBubbleView* bubble_view) { |
| 302 HideBubbleWithView(bubble_view); | 312 HideBubbleWithView(bubble_view); |
| 303 } | 313 } |
| 304 | 314 |
| 305 void PaletteTray::HidePalette() { | 315 void PaletteTray::HidePalette() { |
| 316 is_palette_auto_opened = false; | |
| 317 num_actions_in_palette = 0; | |
| 306 bubble_.reset(); | 318 bubble_.reset(); |
| 307 } | 319 } |
| 308 | 320 |
| 321 void PaletteTray::RecordPaletteMetrics(ash::PaletteTrayOptions option) { | |
| 322 if (option == ash::PaletteTrayOptions::PALETTE_OPTIONS_COUNT) | |
|
jdufault
2016/09/02 21:54:30
Do we want to DCHECK on this?
xiaoyinh(OOO Sep 11-29)
2016/09/06 17:40:05
Added. Thanks
| |
| 323 return; | |
| 324 | |
| 325 if (is_palette_auto_opened) | |
|
Ilya Sherman
2016/09/02 21:39:30
nit: Please use curly braces, since the body spans
jdufault
2016/09/02 21:54:30
nit: add {} for both if/else
xiaoyinh(OOO Sep 11-29)
2016/09/06 17:40:05
Done.
xiaoyinh(OOO Sep 11-29)
2016/09/06 17:40:05
Done.
| |
| 326 UMA_HISTOGRAM_ENUMERATION("Ash.Shelf.PaletteUsage.AutoOpened", option, | |
| 327 ash::PaletteTrayOptions::PALETTE_OPTIONS_COUNT); | |
| 328 else | |
| 329 UMA_HISTOGRAM_ENUMERATION("Ash.Shelf.PaletteUsage", option, | |
| 330 ash::PaletteTrayOptions::PALETTE_OPTIONS_COUNT); | |
| 331 } | |
| 332 | |
| 309 bool PaletteTray::ShouldBlockShelfAutoHide() const { | 333 bool PaletteTray::ShouldBlockShelfAutoHide() const { |
| 310 return !!bubble_; | 334 return !!bubble_; |
| 311 } | 335 } |
| 312 | 336 |
| 313 void PaletteTray::OnActiveToolChanged() { | 337 void PaletteTray::OnActiveToolChanged() { |
| 338 ++num_actions_in_palette; | |
| 314 UpdateTrayIcon(); | 339 UpdateTrayIcon(); |
| 315 } | 340 } |
| 316 | 341 |
| 317 WmWindow* PaletteTray::GetWindow() { | 342 WmWindow* PaletteTray::GetWindow() { |
| 318 return shelf()->GetWindow(); | 343 return shelf()->GetWindow(); |
| 319 } | 344 } |
| 320 | 345 |
| 321 void PaletteTray::SetShelfAlignment(ShelfAlignment alignment) { | 346 void PaletteTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 322 if (alignment == shelf_alignment()) | 347 if (alignment == shelf_alignment()) |
| 323 return; | 348 return; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 346 void PaletteTray::UpdateTrayIcon() { | 371 void PaletteTray::UpdateTrayIcon() { |
| 347 gfx::VectorIconId icon = palette_tool_manager_->GetActiveTrayIcon( | 372 gfx::VectorIconId icon = palette_tool_manager_->GetActiveTrayIcon( |
| 348 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)); | 373 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)); |
| 349 icon_->SetImage(CreateVectorIcon(icon, kShelfIconSize, kShelfIconColor)); | 374 icon_->SetImage(CreateVectorIcon(icon, kShelfIconSize, kShelfIconColor)); |
| 350 } | 375 } |
| 351 | 376 |
| 352 void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) { | 377 void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) { |
| 353 if (!WmShell::Get()->palette_delegate()->ShouldAutoOpenPalette()) | 378 if (!WmShell::Get()->palette_delegate()->ShouldAutoOpenPalette()) |
| 354 return; | 379 return; |
| 355 | 380 |
| 356 if (stylus_state == ui::StylusState::REMOVED && !bubble_) | 381 if (stylus_state == ui::StylusState::REMOVED && !bubble_) { |
| 382 is_palette_auto_opened = true; | |
| 357 ShowPalette(); | 383 ShowPalette(); |
| 358 else if (stylus_state == ui::StylusState::INSERTED && bubble_) | 384 } else if (stylus_state == ui::StylusState::INSERTED && bubble_) { |
| 359 bubble_.reset(); | 385 HidePalette(); |
| 386 } | |
| 360 } | 387 } |
| 361 | 388 |
| 362 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { | 389 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { |
| 363 if (!enabled) | 390 if (!enabled) |
| 364 SetVisible(false); | 391 SetVisible(false); |
| 365 else | 392 else |
| 366 UpdateIconVisibility(); | 393 UpdateIconVisibility(); |
| 367 } | 394 } |
| 368 | 395 |
| 369 void PaletteTray::UpdateIconVisibility() { | 396 void PaletteTray::UpdateIconVisibility() { |
| 370 SessionStateDelegate* session_state_delegate = | 397 SessionStateDelegate* session_state_delegate = |
| 371 WmShell::Get()->GetSessionStateDelegate(); | 398 WmShell::Get()->GetSessionStateDelegate(); |
| 372 | 399 |
| 373 SetVisible(!session_state_delegate->IsScreenLocked() && | 400 SetVisible(!session_state_delegate->IsScreenLocked() && |
| 374 session_state_delegate->GetSessionState() == | 401 session_state_delegate->GetSessionState() == |
| 375 SessionStateDelegate::SESSION_STATE_ACTIVE && | 402 SessionStateDelegate::SESSION_STATE_ACTIVE && |
| 376 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != | 403 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != |
| 377 LoginStatus::KIOSK_APP); | 404 LoginStatus::KIOSK_APP); |
| 378 } | 405 } |
| 379 | 406 |
| 380 } // namespace ash | 407 } // namespace ash |
| OLD | NEW |