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

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

Issue 2234203002: Auto open and close the palette on an eject event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tool-note
Patch Set: Use weak ptr 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
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/palette_delegate.h"
7 #include "ash/common/shelf/shelf_constants.h" 8 #include "ash/common/shelf/shelf_constants.h"
8 #include "ash/common/shelf/wm_shelf.h" 9 #include "ash/common/shelf/wm_shelf.h"
9 #include "ash/common/shelf/wm_shelf_util.h" 10 #include "ash/common/shelf/wm_shelf_util.h"
10 #include "ash/common/shell_window_ids.h" 11 #include "ash/common/shell_window_ids.h"
11 #include "ash/common/system/chromeos/palette/palette_tool_manager.h" 12 #include "ash/common/system/chromeos/palette/palette_tool_manager.h"
12 #include "ash/common/system/chromeos/palette/palette_utils.h" 13 #include "ash/common/system/chromeos/palette/palette_utils.h"
13 #include "ash/common/system/tray/system_tray_delegate.h" 14 #include "ash/common/system/tray/system_tray_delegate.h"
14 #include "ash/common/system/tray/tray_bubble_wrapper.h" 15 #include "ash/common/system/tray/tray_bubble_wrapper.h"
15 #include "ash/common/system/tray/tray_constants.h" 16 #include "ash/common/system/tray/tray_constants.h"
16 #include "ash/common/system/tray/tray_popup_header_button.h" 17 #include "ash/common/system/tray/tray_popup_header_button.h"
17 #include "ash/common/wm_lookup.h" 18 #include "ash/common/wm_lookup.h"
18 #include "ash/common/wm_root_window_controller.h" 19 #include "ash/common/wm_root_window_controller.h"
19 #include "ash/common/wm_shell.h" 20 #include "ash/common/wm_shell.h"
20 #include "ash/common/wm_window.h" 21 #include "ash/common/wm_window.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"
26 #include "ui/events/devices/stylus_state.h"
25 #include "ui/gfx/paint_vector_icon.h" 27 #include "ui/gfx/paint_vector_icon.h"
26 #include "ui/views/controls/image_view.h" 28 #include "ui/views/controls/image_view.h"
27 #include "ui/views/controls/label.h" 29 #include "ui/views/controls/label.h"
28 #include "ui/views/controls/separator.h" 30 #include "ui/views/controls/separator.h"
29 #include "ui/views/layout/box_layout.h" 31 #include "ui/views/layout/box_layout.h"
30 #include "ui/views/layout/fill_layout.h" 32 #include "ui/views/layout/fill_layout.h"
31 33
32 namespace ash { 34 namespace ash {
33 35
34 namespace { 36 namespace {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 ash::TrayPopupHeaderButton* help_button_; 115 ash::TrayPopupHeaderButton* help_button_;
114 PaletteTray* palette_tray_; 116 PaletteTray* palette_tray_;
115 117
116 DISALLOW_COPY_AND_ASSIGN(TitleView); 118 DISALLOW_COPY_AND_ASSIGN(TitleView);
117 }; 119 };
118 120
119 } // namespace 121 } // namespace
120 122
121 PaletteTray::PaletteTray(WmShelf* wm_shelf) 123 PaletteTray::PaletteTray(WmShelf* wm_shelf)
122 : TrayBackgroundView(wm_shelf), 124 : TrayBackgroundView(wm_shelf),
123 palette_tool_manager_(new PaletteToolManager(this)) { 125 palette_tool_manager_(new PaletteToolManager(this)),
126 weak_factory_(this) {
124 PaletteTool::RegisterToolInstances(palette_tool_manager_.get()); 127 PaletteTool::RegisterToolInstances(palette_tool_manager_.get());
125 128
126 SetContentsBackground(); 129 SetContentsBackground();
127 130
128 SetLayoutManager(new views::FillLayout()); 131 SetLayoutManager(new views::FillLayout());
129 icon_ = new views::ImageView(); 132 icon_ = new views::ImageView();
130 UpdateTrayIcon(); 133 UpdateTrayIcon();
131 134
132 SetIconBorderForShelfAlignment(); 135 SetIconBorderForShelfAlignment();
133 tray_container()->AddChildView(icon_); 136 tray_container()->AddChildView(icon_);
134 137
135 WmShell::Get()->AddShellObserver(this); 138 WmShell::Get()->AddShellObserver(this);
136 WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this); 139 WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this);
140 if (WmShell::Get()->palette_delegate()) {
141 WmShell::Get()->palette_delegate()->SetStylusStateChangedCallback(
142 base::Bind(&PaletteTray::OnStylusStateChanged,
143 weak_factory_.GetWeakPtr()));
144 }
137 145
138 UpdateIconVisibility(); 146 UpdateIconVisibility();
139 } 147 }
140 148
141 PaletteTray::~PaletteTray() { 149 PaletteTray::~PaletteTray() {
142 if (bubble_) 150 if (bubble_)
143 bubble_->bubble_view()->reset_delegate(); 151 bubble_->bubble_view()->reset_delegate();
144 152
145 WmShell::Get()->RemoveShellObserver(this); 153 WmShell::Get()->RemoveShellObserver(this);
146 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this); 154 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 host->AddChildView(view.view); 211 host->AddChildView(view.view);
204 } 212 }
205 } 213 }
206 214
207 void PaletteTray::SessionStateChanged( 215 void PaletteTray::SessionStateChanged(
208 SessionStateDelegate::SessionState state) { 216 SessionStateDelegate::SessionState state) {
209 UpdateIconVisibility(); 217 UpdateIconVisibility();
210 } 218 }
211 219
212 void PaletteTray::ClickedOutsideBubble() { 220 void PaletteTray::ClickedOutsideBubble() {
213 HidePalette(); 221 bubble_.reset();
214 } 222 }
215 223
216 base::string16 PaletteTray::GetAccessibleNameForTray() { 224 base::string16 PaletteTray::GetAccessibleNameForTray() {
217 return l10n_util::GetStringUTF16(IDS_ASH_PALETTE_TITLE); 225 return l10n_util::GetStringUTF16(IDS_ASH_PALETTE_TITLE);
218 } 226 }
219 227
220 void PaletteTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { 228 void PaletteTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) {
221 if (bubble_->bubble_view() == bubble_view) 229 if (bubble_->bubble_view() == bubble_view)
222 bubble_.reset(); 230 bubble_.reset();
223 } 231 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 kVerticalShelfVerticalPadding, kVerticalShelfHorizontalPadding))); 316 kVerticalShelfVerticalPadding, kVerticalShelfHorizontalPadding)));
309 } 317 }
310 } 318 }
311 319
312 void PaletteTray::UpdateTrayIcon() { 320 void PaletteTray::UpdateTrayIcon() {
313 gfx::VectorIconId icon = palette_tool_manager_->GetActiveTrayIcon( 321 gfx::VectorIconId icon = palette_tool_manager_->GetActiveTrayIcon(
314 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)); 322 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE));
315 icon_->SetImage(CreateVectorIcon(icon, kShelfIconSize, kShelfIconColor)); 323 icon_->SetImage(CreateVectorIcon(icon, kShelfIconSize, kShelfIconColor));
316 } 324 }
317 325
326 void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) {
327 if (!WmShell::Get()->palette_delegate()->ShouldAutoOpenPalette())
328 return;
329
330 if (stylus_state == ui::StylusState::REMOVED && !bubble_)
331 OpenBubble();
332 else if (stylus_state == ui::StylusState::INSERTED && bubble_)
333 bubble_.reset();
334 }
335
318 void PaletteTray::UpdateIconVisibility() { 336 void PaletteTray::UpdateIconVisibility() {
319 if (!IsPaletteEnabled()) 337 if (!IsPaletteEnabled())
320 return; 338 return;
321 339
322 SessionStateDelegate* session_state_delegate = 340 SessionStateDelegate* session_state_delegate =
323 WmShell::Get()->GetSessionStateDelegate(); 341 WmShell::Get()->GetSessionStateDelegate();
324 342
325 SetVisible(!session_state_delegate->IsScreenLocked() && 343 SetVisible(!session_state_delegate->IsScreenLocked() &&
326 session_state_delegate->GetSessionState() == 344 session_state_delegate->GetSessionState() ==
327 SessionStateDelegate::SESSION_STATE_ACTIVE && 345 SessionStateDelegate::SESSION_STATE_ACTIVE &&
328 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != 346 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() !=
329 LoginStatus::KIOSK_APP); 347 LoginStatus::KIOSK_APP);
330 } 348 }
331 349
332 } // namespace ash 350 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/palette/palette_tray.h ('k') | ash/common/test/test_palette_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698