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

Unified Diff: ash/common/system/chromeos/palette/palette_tray.cc

Issue 2644713002: cros: Use runtime stylus detection for ash palette. (Closed)
Patch Set: Initial upload Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: ash/common/system/chromeos/palette/palette_tray.cc
diff --git a/ash/common/system/chromeos/palette/palette_tray.cc b/ash/common/system/chromeos/palette/palette_tray.cc
index affb069a96ac98dc68c1b26ba55b27bc308c4e60..bed334c52a2b910e64e267f244229df7d7996b95 100644
--- a/ash/common/system/chromeos/palette/palette_tray.cc
+++ b/ash/common/system/chromeos/palette/palette_tray.cc
@@ -29,6 +29,7 @@
#include "grit/ash_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/events/devices/input_device_manager.h"
#include "ui/events/devices/stylus_state.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/paint_vector_icon.h"
@@ -167,9 +168,6 @@ PaletteTray::PaletteTray(WmShelf* wm_shelf)
: TrayBackgroundView(wm_shelf),
palette_tool_manager_(new PaletteToolManager(this)),
weak_factory_(this) {
- // PaletteTray should only be instantiated if the palette feature is enabled.
- DCHECK(IsPaletteFeatureEnabled());
-
PaletteTool::RegisterToolInstances(palette_tool_manager_.get());
if (MaterialDesignController::IsShelfMaterial()) {
@@ -188,17 +186,14 @@ PaletteTray::PaletteTray(WmShelf* wm_shelf)
WmShell::Get()->AddShellObserver(this);
WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this);
- if (WmShell::Get()->palette_delegate()) {
- WmShell::Get()->palette_delegate()->SetStylusStateChangedCallback(
- base::Bind(&PaletteTray::OnStylusStateChanged,
- weak_factory_.GetWeakPtr()));
- }
+ ui::InputDeviceManager::GetInstance()->AddObserver(this);
}
PaletteTray::~PaletteTray() {
if (bubble_)
bubble_->bubble_view()->reset_delegate();
+ ui::InputDeviceManager::GetInstance()->RemoveObserver(this);
WmShell::Get()->RemoveShellObserver(this);
WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this);
}
@@ -304,6 +299,33 @@ void PaletteTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) {
HidePalette();
}
+void PaletteTray::OnTouchscreenDeviceConfigurationChanged() {
+ UpdateIconVisibility();
+}
+
+void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) {
+ PaletteDelegate* palette_delegate = WmShell::Get()->palette_delegate();
+
+ // Don't do anything if the palette should not be shown or if the user has
+ // disabled it all-together.
+ if (!IsInUserSession() || !palette_delegate->ShouldShowPalette())
+ return;
+
+ // Auto show/hide the palette if allowed by the user.
+ if (palette_delegate->ShouldAutoOpenPalette()) {
+ if (stylus_state == ui::StylusState::REMOVED && !bubble_) {
+ is_bubble_auto_opened_ = true;
+ ShowPalette();
+ } else if (stylus_state == ui::StylusState::INSERTED && bubble_) {
+ HidePalette();
+ }
+ }
+
+ // Disable any active modes if the stylus has been inserted.
+ if (stylus_state == ui::StylusState::INSERTED)
+ palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE);
+}
+
void PaletteTray::BubbleViewDestroyed() {
palette_tool_manager_->NotifyViewsDestroyed();
SetIsActive(false);
@@ -396,12 +418,14 @@ void PaletteTray::AnchorUpdated() {
}
void PaletteTray::Initialize() {
- // OnPaletteEnabledPrefChanged will get called with the initial pref value,
- // which will take care of showing the palette.
- palette_enabled_subscription_ =
- WmShell::Get()->palette_delegate()->AddPaletteEnableListener(
- base::Bind(&PaletteTray::OnPaletteEnabledPrefChanged,
- weak_factory_.GetWeakPtr()));
+ PaletteDelegate* delegate = WmShell::Get()->palette_delegate();
+ if (delegate) {
stevenjb 2017/01/21 00:23:50 if (!delegate) return;
jdufault 2017/01/25 00:53:15 Done.
+ // OnPaletteEnabledPrefChanged will get called with the initial pref value,
+ // which will take care of showing the palette.
+ palette_enabled_subscription_ = delegate->AddPaletteEnableListener(
+ base::Bind(&PaletteTray::OnPaletteEnabledPrefChanged,
+ weak_factory_.GetWeakPtr()));
+ }
}
void PaletteTray::SetIconBorderForShelfAlignment() {
@@ -423,29 +447,6 @@ void PaletteTray::UpdateTrayIcon() {
kTrayIconSize, kShelfIconColor));
}
-void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) {
- PaletteDelegate* palette_delegate = WmShell::Get()->palette_delegate();
-
- // Don't do anything if the palette should not be shown or if the user has
- // disabled it all-together.
- if (!IsInUserSession() || !palette_delegate->ShouldShowPalette())
- return;
-
- // Auto show/hide the palette if allowed by the user.
- if (palette_delegate->ShouldAutoOpenPalette()) {
- if (stylus_state == ui::StylusState::REMOVED && !bubble_) {
- is_bubble_auto_opened_ = true;
- ShowPalette();
- } else if (stylus_state == ui::StylusState::INSERTED && bubble_) {
- HidePalette();
- }
- }
-
- // Disable any active modes if the stylus has been inserted.
- if (stylus_state == ui::StylusState::INSERTED)
- palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE);
-}
-
void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) {
is_palette_enabled_ = enabled;
@@ -458,7 +459,7 @@ void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) {
}
void PaletteTray::UpdateIconVisibility() {
- SetVisible(is_palette_enabled_ && IsInUserSession());
+ SetVisible(is_palette_enabled_ && HasStylusInput() && IsInUserSession());
}
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698