Chromium Code Reviews| 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/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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 | 129 |
| 128 SetLayoutManager(new views::FillLayout()); | 130 SetLayoutManager(new views::FillLayout()); |
| 129 icon_ = new views::ImageView(); | 131 icon_ = new views::ImageView(); |
| 130 UpdateTrayIcon(); | 132 UpdateTrayIcon(); |
| 131 | 133 |
| 132 SetIconBorderForShelfAlignment(); | 134 SetIconBorderForShelfAlignment(); |
| 133 tray_container()->AddChildView(icon_); | 135 tray_container()->AddChildView(icon_); |
| 134 | 136 |
| 135 WmShell::Get()->AddShellObserver(this); | 137 WmShell::Get()->AddShellObserver(this); |
| 136 WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this); | 138 WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this); |
| 139 if (WmShell::Get()->palette_delegate()) { | |
| 140 WmShell::Get()->palette_delegate()->SetStylusStateChangedCallback( | |
| 141 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.
| |
| 142 } | |
| 137 | 143 |
| 138 UpdateIconVisibility(); | 144 UpdateIconVisibility(); |
| 139 } | 145 } |
| 140 | 146 |
| 141 PaletteTray::~PaletteTray() { | 147 PaletteTray::~PaletteTray() { |
| 142 if (bubble_) | 148 if (bubble_) |
| 143 bubble_->bubble_view()->reset_delegate(); | 149 bubble_->bubble_view()->reset_delegate(); |
| 144 | 150 |
| 145 WmShell::Get()->RemoveShellObserver(this); | 151 WmShell::Get()->RemoveShellObserver(this); |
| 146 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this); | 152 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 host->AddChildView(view.view); | 209 host->AddChildView(view.view); |
| 204 } | 210 } |
| 205 } | 211 } |
| 206 | 212 |
| 207 void PaletteTray::SessionStateChanged( | 213 void PaletteTray::SessionStateChanged( |
| 208 SessionStateDelegate::SessionState state) { | 214 SessionStateDelegate::SessionState state) { |
| 209 UpdateIconVisibility(); | 215 UpdateIconVisibility(); |
| 210 } | 216 } |
| 211 | 217 |
| 212 void PaletteTray::ClickedOutsideBubble() { | 218 void PaletteTray::ClickedOutsideBubble() { |
| 213 HidePalette(); | 219 bubble_.reset(); |
| 214 } | 220 } |
| 215 | 221 |
| 216 base::string16 PaletteTray::GetAccessibleNameForTray() { | 222 base::string16 PaletteTray::GetAccessibleNameForTray() { |
| 217 return l10n_util::GetStringUTF16(IDS_ASH_PALETTE_TITLE); | 223 return l10n_util::GetStringUTF16(IDS_ASH_PALETTE_TITLE); |
| 218 } | 224 } |
| 219 | 225 |
| 220 void PaletteTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { | 226 void PaletteTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { |
| 221 if (bubble_->bubble_view() == bubble_view) | 227 if (bubble_->bubble_view() == bubble_view) |
| 222 bubble_.reset(); | 228 bubble_.reset(); |
| 223 } | 229 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 kVerticalShelfVerticalPadding, kVerticalShelfHorizontalPadding))); | 314 kVerticalShelfVerticalPadding, kVerticalShelfHorizontalPadding))); |
| 309 } | 315 } |
| 310 } | 316 } |
| 311 | 317 |
| 312 void PaletteTray::UpdateTrayIcon() { | 318 void PaletteTray::UpdateTrayIcon() { |
| 313 gfx::VectorIconId icon = palette_tool_manager_->GetActiveTrayIcon( | 319 gfx::VectorIconId icon = palette_tool_manager_->GetActiveTrayIcon( |
| 314 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)); | 320 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)); |
| 315 icon_->SetImage(CreateVectorIcon(icon, kShelfIconSize, kShelfIconColor)); | 321 icon_->SetImage(CreateVectorIcon(icon, kShelfIconSize, kShelfIconColor)); |
| 316 } | 322 } |
| 317 | 323 |
| 324 void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) { | |
| 325 if (!WmShell::Get()->palette_delegate()->ShouldAutoOpenPalette()) | |
| 326 return; | |
| 327 | |
| 328 if (stylus_state == ui::StylusState::REMOVED && !bubble_) | |
| 329 OpenBubble(); | |
| 330 else if (stylus_state == ui::StylusState::INSERTED && bubble_) | |
| 331 bubble_.reset(); | |
| 332 } | |
| 333 | |
| 318 void PaletteTray::UpdateIconVisibility() { | 334 void PaletteTray::UpdateIconVisibility() { |
| 319 if (!IsPaletteEnabled()) | 335 if (!IsPaletteEnabled()) |
| 320 return; | 336 return; |
| 321 | 337 |
| 322 SessionStateDelegate* session_state_delegate = | 338 SessionStateDelegate* session_state_delegate = |
| 323 WmShell::Get()->GetSessionStateDelegate(); | 339 WmShell::Get()->GetSessionStateDelegate(); |
| 324 | 340 |
| 325 SetVisible(!session_state_delegate->IsScreenLocked() && | 341 SetVisible(!session_state_delegate->IsScreenLocked() && |
| 326 session_state_delegate->GetSessionState() == | 342 session_state_delegate->GetSessionState() == |
| 327 SessionStateDelegate::SESSION_STATE_ACTIVE && | 343 SessionStateDelegate::SESSION_STATE_ACTIVE && |
| 328 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != | 344 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != |
| 329 LoginStatus::KIOSK_APP); | 345 LoginStatus::KIOSK_APP); |
| 330 } | 346 } |
| 331 | 347 |
| 332 } // namespace ash | 348 } // namespace ash |
| OLD | NEW |