Chromium Code Reviews| 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 1a13c9c4ba9ffe9af7800b322415cdbfa9d066d7..a485f171ee8b5811481f45b364c574b1290033f9 100644 |
| --- a/ash/common/system/chromeos/palette/palette_tray.cc |
| +++ b/ash/common/system/chromeos/palette/palette_tray.cc |
| @@ -4,6 +4,7 @@ |
| #include "ash/common/system/chromeos/palette/palette_tray.h" |
| +#include "ash/common/palette_delegate.h" |
| #include "ash/common/shelf/shelf_constants.h" |
| #include "ash/common/shelf/wm_shelf.h" |
| #include "ash/common/shelf/wm_shelf_util.h" |
| @@ -22,6 +23,7 @@ |
| #include "grit/ash_strings.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/resource/resource_bundle.h" |
| +#include "ui/events/devices/stylus_state.h" |
| #include "ui/gfx/paint_vector_icon.h" |
| #include "ui/views/controls/image_view.h" |
| #include "ui/views/controls/label.h" |
| @@ -134,6 +136,10 @@ 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, base::Unretained(this))); |
|
stevenjb
2016/08/25 22:48:56
Need to pass this as a weak_ptr. It's always iffy
jdufault
2016/08/25 23:09:15
Done.
|
| + } |
| UpdateIconVisibility(); |
| } |
| @@ -210,7 +216,7 @@ void PaletteTray::SessionStateChanged( |
| } |
| void PaletteTray::ClickedOutsideBubble() { |
| - HidePalette(); |
| + bubble_.reset(); |
| } |
| base::string16 PaletteTray::GetAccessibleNameForTray() { |
| @@ -315,6 +321,16 @@ void PaletteTray::UpdateTrayIcon() { |
| icon_->SetImage(CreateVectorIcon(icon, kShelfIconSize, kShelfIconColor)); |
| } |
| +void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) { |
| + if (!WmShell::Get()->palette_delegate()->ShouldAutoOpenPalette()) |
| + return; |
| + |
| + if (stylus_state == ui::StylusState::REMOVED && !bubble_) |
| + OpenBubble(); |
| + else if (stylus_state == ui::StylusState::INSERTED && bubble_) |
| + bubble_.reset(); |
| +} |
| + |
| void PaletteTray::UpdateIconVisibility() { |
| if (!IsPaletteEnabled()) |
| return; |