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_macros.h" |
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_->RecordPaletteOptionsUsage( |
| 113 PaletteTrayOptions::PALETTE_SETTINGS_BUTTON); |
111 WmShell::Get()->system_tray_delegate()->ShowPaletteSettings(); | 114 WmShell::Get()->system_tray_delegate()->ShowPaletteSettings(); |
112 palette_tray_->HidePalette(); | 115 palette_tray_->HidePalette(); |
113 } else if (sender == help_button_) { | 116 } else if (sender == help_button_) { |
| 117 palette_tray_->RecordPaletteOptionsUsage( |
| 118 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_bubble_ == 0) |
| 182 RecordPaletteOptionsUsage(PaletteTrayOptions::PALETTE_CLOSED_NO_ACTION); |
| 183 HidePalette(); |
177 return true; | 184 return true; |
178 } | 185 } |
179 | 186 |
180 return ShowPalette(); | 187 return ShowPalette(); |
181 } | 188 } |
182 | 189 |
183 bool PaletteTray::ShowPalette() { | 190 bool PaletteTray::ShowPalette() { |
184 if (bubble_) | 191 if (bubble_) |
185 return false; | 192 return false; |
186 | 193 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 void PaletteTray::SessionStateChanged( | 243 void PaletteTray::SessionStateChanged( |
237 SessionStateDelegate::SessionState state) { | 244 SessionStateDelegate::SessionState state) { |
238 UpdateIconVisibility(); | 245 UpdateIconVisibility(); |
239 } | 246 } |
240 | 247 |
241 void PaletteTray::OnLockStateChanged(bool locked) { | 248 void PaletteTray::OnLockStateChanged(bool locked) { |
242 UpdateIconVisibility(); | 249 UpdateIconVisibility(); |
243 } | 250 } |
244 | 251 |
245 void PaletteTray::ClickedOutsideBubble() { | 252 void PaletteTray::ClickedOutsideBubble() { |
246 bubble_.reset(); | 253 if (num_actions_in_bubble_ == 0) |
| 254 RecordPaletteOptionsUsage(PaletteTrayOptions::PALETTE_CLOSED_NO_ACTION); |
| 255 HidePalette(); |
247 } | 256 } |
248 | 257 |
249 base::string16 PaletteTray::GetAccessibleNameForTray() { | 258 base::string16 PaletteTray::GetAccessibleNameForTray() { |
250 return l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_TITLE); | 259 return l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_TITLE); |
251 } | 260 } |
252 | 261 |
253 void PaletteTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { | 262 void PaletteTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { |
254 if (bubble_->bubble_view() == bubble_view) | 263 if (bubble_->bubble_view() == bubble_view) |
255 bubble_.reset(); | 264 HidePalette(); |
256 } | 265 } |
257 | 266 |
258 void PaletteTray::BubbleViewDestroyed() { | 267 void PaletteTray::BubbleViewDestroyed() { |
259 palette_tool_manager_->NotifyViewsDestroyed(); | 268 palette_tool_manager_->NotifyViewsDestroyed(); |
260 SetDrawBackgroundAsActive(false); | 269 SetDrawBackgroundAsActive(false); |
261 } | 270 } |
262 | 271 |
263 void PaletteTray::OnMouseEnteredView() {} | 272 void PaletteTray::OnMouseEnteredView() {} |
264 | 273 |
265 void PaletteTray::OnMouseExitedView() {} | 274 void PaletteTray::OnMouseExitedView() {} |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 ->GetRootWindowController() | 312 ->GetRootWindowController() |
304 ->ConfigureWidgetInitParamsForContainer( | 313 ->ConfigureWidgetInitParamsForContainer( |
305 bubble_widget, kShellWindowId_SettingBubbleContainer, params); | 314 bubble_widget, kShellWindowId_SettingBubbleContainer, params); |
306 } | 315 } |
307 | 316 |
308 void PaletteTray::HideBubble(const views::TrayBubbleView* bubble_view) { | 317 void PaletteTray::HideBubble(const views::TrayBubbleView* bubble_view) { |
309 HideBubbleWithView(bubble_view); | 318 HideBubbleWithView(bubble_view); |
310 } | 319 } |
311 | 320 |
312 void PaletteTray::HidePalette() { | 321 void PaletteTray::HidePalette() { |
| 322 is_bubble_auto_opened_ = false; |
| 323 num_actions_in_bubble_ = 0; |
313 bubble_.reset(); | 324 bubble_.reset(); |
314 } | 325 } |
315 | 326 |
| 327 void PaletteTray::RecordPaletteOptionsUsage(PaletteTrayOptions option) { |
| 328 DCHECK_NE(option, PaletteTrayOptions::PALETTE_OPTIONS_COUNT); |
| 329 |
| 330 if (is_bubble_auto_opened_) { |
| 331 UMA_HISTOGRAM_ENUMERATION("Ash.Shelf.Palette.Usage.AutoOpened", option, |
| 332 PaletteTrayOptions::PALETTE_OPTIONS_COUNT); |
| 333 } else { |
| 334 UMA_HISTOGRAM_ENUMERATION("Ash.Shelf.Palette.Usage", option, |
| 335 PaletteTrayOptions::PALETTE_OPTIONS_COUNT); |
| 336 } |
| 337 } |
| 338 |
| 339 void PaletteTray::RecordPaletteModeCancellation(PaletteModeCancelType type) { |
| 340 if (type == PaletteModeCancelType::PALETTE_MODE_CANCEL_TYPE_COUNT) |
| 341 return; |
| 342 |
| 343 UMA_HISTOGRAM_ENUMERATION( |
| 344 "Ash.Shelf.Palette.ModeCancellation", type, |
| 345 PaletteModeCancelType::PALETTE_MODE_CANCEL_TYPE_COUNT); |
| 346 } |
| 347 |
316 bool PaletteTray::ShouldBlockShelfAutoHide() const { | 348 bool PaletteTray::ShouldBlockShelfAutoHide() const { |
317 return !!bubble_; | 349 return !!bubble_; |
318 } | 350 } |
319 | 351 |
320 void PaletteTray::OnActiveToolChanged() { | 352 void PaletteTray::OnActiveToolChanged() { |
| 353 ++num_actions_in_bubble_; |
321 UpdateTrayIcon(); | 354 UpdateTrayIcon(); |
322 } | 355 } |
323 | 356 |
324 WmWindow* PaletteTray::GetWindow() { | 357 WmWindow* PaletteTray::GetWindow() { |
325 return shelf()->GetWindow(); | 358 return shelf()->GetWindow(); |
326 } | 359 } |
327 | 360 |
328 void PaletteTray::SetShelfAlignment(ShelfAlignment alignment) { | 361 void PaletteTray::SetShelfAlignment(ShelfAlignment alignment) { |
329 if (alignment == shelf_alignment()) | 362 if (alignment == shelf_alignment()) |
330 return; | 363 return; |
(...skipping 23 matching lines...) Expand all Loading... |
354 icon_->SetImage(CreateVectorIcon( | 387 icon_->SetImage(CreateVectorIcon( |
355 palette_tool_manager_->GetActiveTrayIcon( | 388 palette_tool_manager_->GetActiveTrayIcon( |
356 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)), | 389 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)), |
357 kShelfIconSize, kShelfIconColor)); | 390 kShelfIconSize, kShelfIconColor)); |
358 } | 391 } |
359 | 392 |
360 void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) { | 393 void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) { |
361 if (!WmShell::Get()->palette_delegate()->ShouldAutoOpenPalette()) | 394 if (!WmShell::Get()->palette_delegate()->ShouldAutoOpenPalette()) |
362 return; | 395 return; |
363 | 396 |
364 if (stylus_state == ui::StylusState::REMOVED && !bubble_) | 397 if (stylus_state == ui::StylusState::REMOVED && !bubble_) { |
| 398 is_bubble_auto_opened_ = true; |
365 ShowPalette(); | 399 ShowPalette(); |
366 else if (stylus_state == ui::StylusState::INSERTED && bubble_) | 400 } else if (stylus_state == ui::StylusState::INSERTED && bubble_) { |
367 bubble_.reset(); | 401 HidePalette(); |
| 402 } |
368 } | 403 } |
369 | 404 |
370 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { | 405 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { |
371 if (!enabled) | 406 if (!enabled) |
372 SetVisible(false); | 407 SetVisible(false); |
373 else | 408 else |
374 UpdateIconVisibility(); | 409 UpdateIconVisibility(); |
375 } | 410 } |
376 | 411 |
377 void PaletteTray::UpdateIconVisibility() { | 412 void PaletteTray::UpdateIconVisibility() { |
378 SessionStateDelegate* session_state_delegate = | 413 SessionStateDelegate* session_state_delegate = |
379 WmShell::Get()->GetSessionStateDelegate(); | 414 WmShell::Get()->GetSessionStateDelegate(); |
380 | 415 |
381 SetVisible(!session_state_delegate->IsScreenLocked() && | 416 SetVisible(!session_state_delegate->IsScreenLocked() && |
382 session_state_delegate->GetSessionState() == | 417 session_state_delegate->GetSessionState() == |
383 SessionStateDelegate::SESSION_STATE_ACTIVE && | 418 SessionStateDelegate::SESSION_STATE_ACTIVE && |
384 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != | 419 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != |
385 LoginStatus::KIOSK_APP); | 420 LoginStatus::KIOSK_APP); |
386 } | 421 } |
387 | 422 |
388 } // namespace ash | 423 } // namespace ash |
OLD | NEW |