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

Side by Side Diff: ash/common/system/chromeos/palette/palette_tray.cc

Issue 2346833003: cros: Hide stylus tools on various sign-in screens, disable active mode when inserting stylus. (Closed)
Patch Set: Initial upload Created 4 years, 3 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
« no previous file with comments | « ash/common/system/chromeos/palette/palette_tool_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 const int kIconSize = 20; 62 const int kIconSize = 20;
63 63
64 // Creates a separator. 64 // Creates a separator.
65 views::Separator* CreateSeparator(views::Separator::Orientation orientation) { 65 views::Separator* CreateSeparator(views::Separator::Orientation orientation) {
66 views::Separator* separator = 66 views::Separator* separator =
67 new views::Separator(views::Separator::HORIZONTAL); 67 new views::Separator(views::Separator::HORIZONTAL);
68 separator->SetColor(ash::kBorderDarkColor); 68 separator->SetColor(ash::kBorderDarkColor);
69 return separator; 69 return separator;
70 } 70 }
71 71
72 // Returns true if we are in a user session that can show the stylus tools.
73 bool IsInUserSession() {
74 SessionStateDelegate* session_state_delegate =
75 WmShell::Get()->GetSessionStateDelegate();
76 return !session_state_delegate->IsUserSessionBlocked() &&
77 session_state_delegate->GetSessionState() ==
78 SessionStateDelegate::SESSION_STATE_ACTIVE &&
79 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() !=
80 LoginStatus::KIOSK_APP;
81 }
82
72 class TitleView : public views::View, public views::ButtonListener { 83 class TitleView : public views::View, public views::ButtonListener {
73 public: 84 public:
74 explicit TitleView(PaletteTray* palette_tray) : palette_tray_(palette_tray) { 85 explicit TitleView(PaletteTray* palette_tray) : palette_tray_(palette_tray) {
75 auto& rb = ui::ResourceBundle::GetSharedInstance(); 86 auto& rb = ui::ResourceBundle::GetSharedInstance();
76 87
77 auto* box_layout = 88 auto* box_layout =
78 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); 89 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
79 SetLayoutManager(box_layout); 90 SetLayoutManager(box_layout);
80 91
81 views::Label* text_label = 92 views::Label* text_label =
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 host->AddChildView(view.view); 251 host->AddChildView(view.view);
241 } 252 }
242 253
243 void PaletteTray::SessionStateChanged( 254 void PaletteTray::SessionStateChanged(
244 SessionStateDelegate::SessionState state) { 255 SessionStateDelegate::SessionState state) {
245 UpdateIconVisibility(); 256 UpdateIconVisibility();
246 } 257 }
247 258
248 void PaletteTray::OnLockStateChanged(bool locked) { 259 void PaletteTray::OnLockStateChanged(bool locked) {
249 UpdateIconVisibility(); 260 UpdateIconVisibility();
261
262 // The user can eject the stylus during the lock screen transition, which will
263 // open the palette. Make sure to close it if that happens.
264 if (locked)
265 HidePalette();
250 } 266 }
251 267
252 void PaletteTray::ClickedOutsideBubble() { 268 void PaletteTray::ClickedOutsideBubble() {
253 if (num_actions_in_bubble_ == 0) 269 if (num_actions_in_bubble_ == 0)
254 RecordPaletteOptionsUsage(PaletteTrayOptions::PALETTE_CLOSED_NO_ACTION); 270 RecordPaletteOptionsUsage(PaletteTrayOptions::PALETTE_CLOSED_NO_ACTION);
255 HidePalette(); 271 HidePalette();
256 } 272 }
257 273
258 base::string16 PaletteTray::GetAccessibleNameForTray() { 274 base::string16 PaletteTray::GetAccessibleNameForTray() {
259 return l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_TITLE); 275 return l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_TITLE);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 } 400 }
385 401
386 void PaletteTray::UpdateTrayIcon() { 402 void PaletteTray::UpdateTrayIcon() {
387 icon_->SetImage(CreateVectorIcon( 403 icon_->SetImage(CreateVectorIcon(
388 palette_tool_manager_->GetActiveTrayIcon( 404 palette_tool_manager_->GetActiveTrayIcon(
389 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)), 405 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)),
390 kShelfIconSize, kShelfIconColor)); 406 kShelfIconSize, kShelfIconColor));
391 } 407 }
392 408
393 void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) { 409 void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) {
394 if (!WmShell::Get()->palette_delegate()->ShouldAutoOpenPalette()) 410 PaletteDelegate* palette_delegate = WmShell::Get()->palette_delegate();
411
412 // Don't do anything if the palette should not be shown or if the user has
413 // disabled it all-together.
414 if (!IsInUserSession() || !palette_delegate->ShouldShowPalette())
395 return; 415 return;
396 416
397 if (stylus_state == ui::StylusState::REMOVED && !bubble_) { 417 // Auto show/hide the palette if allowed by the user.
398 is_bubble_auto_opened_ = true; 418 if (palette_delegate->ShouldAutoOpenPalette()) {
399 ShowPalette(); 419 if (stylus_state == ui::StylusState::REMOVED && !bubble_) {
400 } else if (stylus_state == ui::StylusState::INSERTED && bubble_) { 420 is_bubble_auto_opened_ = true;
401 HidePalette(); 421 ShowPalette();
422 } else if (stylus_state == ui::StylusState::INSERTED && bubble_) {
423 HidePalette();
424 }
425 }
426
427 // Disable any active modes if the stylus has been inserted.
428 if (stylus_state == ui::StylusState::INSERTED)
429 palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE);
430 }
431
432 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) {
433 if (!enabled) {
434 SetVisible(false);
435 palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE);
436 } else {
437 UpdateIconVisibility();
402 } 438 }
403 } 439 }
404 440
405 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) {
406 if (!enabled)
407 SetVisible(false);
408 else
409 UpdateIconVisibility();
410 }
411
412 void PaletteTray::UpdateIconVisibility() { 441 void PaletteTray::UpdateIconVisibility() {
413 SessionStateDelegate* session_state_delegate = 442 SetVisible(IsInUserSession());
414 WmShell::Get()->GetSessionStateDelegate();
415
416 SetVisible(!session_state_delegate->IsScreenLocked() &&
417 session_state_delegate->GetSessionState() ==
418 SessionStateDelegate::SESSION_STATE_ACTIVE &&
419 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() !=
420 LoginStatus::KIOSK_APP);
421 } 443 }
422 444
423 } // namespace ash 445 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/palette/palette_tool_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698