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 } | |
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_bubble_ == 0) |
248 RecordPaletteOptionsUsage(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_bubble_auto_opened_ = false; | |
317 num_actions_in_bubble_ = 0; | |
306 bubble_.reset(); | 318 bubble_.reset(); |
307 } | 319 } |
308 | 320 |
321 void PaletteTray::RecordPaletteOptionsUsage(PaletteTrayOptions option) { | |
322 DCHECK(option != PaletteTrayOptions::PALETTE_OPTIONS_COUNT); | |
323 | |
324 if (is_bubble_auto_opened_) { | |
325 UMA_HISTOGRAM_ENUMERATION("Ash.Shelf.Palette.Usage.AutoOpened", option, | |
326 PaletteTrayOptions::PALETTE_OPTIONS_COUNT); | |
327 } else { | |
328 UMA_HISTOGRAM_ENUMERATION("Ash.Shelf.Palette.Usage", option, | |
329 PaletteTrayOptions::PALETTE_OPTIONS_COUNT); | |
330 } | |
331 } | |
332 | |
333 void PaletteTray::RecordPaletteModeCancellation(PaletteModeCancelType type) { | |
334 DCHECK(type != PaletteModeCancelType::PALETTE_MODE_CANCEL_TYPE_COUNT); | |
Ilya Sherman
2016/09/06 20:45:32
nit: DCHECK_NE (and ditto above)
xiaoyinh(OOO Sep 11-29)
2016/09/06 22:31:35
Done.
| |
335 UMA_HISTOGRAM_ENUMERATION( | |
336 "Ash.Shelf.Palette.ModeCancellation", type, | |
337 PaletteModeCancelType::PALETTE_MODE_CANCEL_TYPE_COUNT); | |
338 } | |
339 | |
309 bool PaletteTray::ShouldBlockShelfAutoHide() const { | 340 bool PaletteTray::ShouldBlockShelfAutoHide() const { |
310 return !!bubble_; | 341 return !!bubble_; |
311 } | 342 } |
312 | 343 |
313 void PaletteTray::OnActiveToolChanged() { | 344 void PaletteTray::OnActiveToolChanged() { |
345 ++num_actions_in_bubble_; | |
314 UpdateTrayIcon(); | 346 UpdateTrayIcon(); |
315 } | 347 } |
316 | 348 |
317 WmWindow* PaletteTray::GetWindow() { | 349 WmWindow* PaletteTray::GetWindow() { |
318 return shelf()->GetWindow(); | 350 return shelf()->GetWindow(); |
319 } | 351 } |
320 | 352 |
321 void PaletteTray::SetShelfAlignment(ShelfAlignment alignment) { | 353 void PaletteTray::SetShelfAlignment(ShelfAlignment alignment) { |
322 if (alignment == shelf_alignment()) | 354 if (alignment == shelf_alignment()) |
323 return; | 355 return; |
(...skipping 22 matching lines...) Expand all Loading... | |
346 void PaletteTray::UpdateTrayIcon() { | 378 void PaletteTray::UpdateTrayIcon() { |
347 gfx::VectorIconId icon = palette_tool_manager_->GetActiveTrayIcon( | 379 gfx::VectorIconId icon = palette_tool_manager_->GetActiveTrayIcon( |
348 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)); | 380 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)); |
349 icon_->SetImage(CreateVectorIcon(icon, kShelfIconSize, kShelfIconColor)); | 381 icon_->SetImage(CreateVectorIcon(icon, kShelfIconSize, kShelfIconColor)); |
350 } | 382 } |
351 | 383 |
352 void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) { | 384 void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) { |
353 if (!WmShell::Get()->palette_delegate()->ShouldAutoOpenPalette()) | 385 if (!WmShell::Get()->palette_delegate()->ShouldAutoOpenPalette()) |
354 return; | 386 return; |
355 | 387 |
356 if (stylus_state == ui::StylusState::REMOVED && !bubble_) | 388 if (stylus_state == ui::StylusState::REMOVED && !bubble_) { |
389 is_bubble_auto_opened_ = true; | |
357 ShowPalette(); | 390 ShowPalette(); |
358 else if (stylus_state == ui::StylusState::INSERTED && bubble_) | 391 } else if (stylus_state == ui::StylusState::INSERTED && bubble_) { |
359 bubble_.reset(); | 392 HidePalette(); |
393 } | |
360 } | 394 } |
361 | 395 |
362 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { | 396 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { |
363 if (!enabled) | 397 if (!enabled) |
364 SetVisible(false); | 398 SetVisible(false); |
365 else | 399 else |
366 UpdateIconVisibility(); | 400 UpdateIconVisibility(); |
367 } | 401 } |
368 | 402 |
369 void PaletteTray::UpdateIconVisibility() { | 403 void PaletteTray::UpdateIconVisibility() { |
370 SessionStateDelegate* session_state_delegate = | 404 SessionStateDelegate* session_state_delegate = |
371 WmShell::Get()->GetSessionStateDelegate(); | 405 WmShell::Get()->GetSessionStateDelegate(); |
372 | 406 |
373 SetVisible(!session_state_delegate->IsScreenLocked() && | 407 SetVisible(!session_state_delegate->IsScreenLocked() && |
374 session_state_delegate->GetSessionState() == | 408 session_state_delegate->GetSessionState() == |
375 SessionStateDelegate::SESSION_STATE_ACTIVE && | 409 SessionStateDelegate::SESSION_STATE_ACTIVE && |
376 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != | 410 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != |
377 LoginStatus::KIOSK_APP); | 411 LoginStatus::KIOSK_APP); |
378 } | 412 } |
379 | 413 |
380 } // namespace ash | 414 } // namespace ash |
OLD | NEW |