| 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/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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 WmShell::Get()->RemoveShellObserver(this); | 160 WmShell::Get()->RemoveShellObserver(this); |
| 161 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this); | 161 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this); |
| 162 } | 162 } |
| 163 | 163 |
| 164 bool PaletteTray::PerformAction(const ui::Event& event) { | 164 bool PaletteTray::PerformAction(const ui::Event& event) { |
| 165 if (bubble_) { | 165 if (bubble_) { |
| 166 bubble_.reset(); | 166 bubble_.reset(); |
| 167 return true; | 167 return true; |
| 168 } | 168 } |
| 169 | 169 |
| 170 return OpenBubble(); | 170 return ShowPalette(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool PaletteTray::OpenBubble() { | 173 bool PaletteTray::ShowPalette() { |
| 174 if (bubble_) |
| 175 return false; |
| 176 |
| 174 views::TrayBubbleView::InitParams init_params( | 177 views::TrayBubbleView::InitParams init_params( |
| 175 views::TrayBubbleView::ANCHOR_TYPE_TRAY, GetAnchorAlignment(), | 178 views::TrayBubbleView::ANCHOR_TYPE_TRAY, GetAnchorAlignment(), |
| 176 kPaletteWidth, kPaletteWidth); | 179 kPaletteWidth, kPaletteWidth); |
| 177 init_params.first_item_has_no_margin = true; | 180 init_params.first_item_has_no_margin = true; |
| 178 init_params.can_activate = true; | 181 init_params.can_activate = true; |
| 179 init_params.close_on_deactivate = true; | 182 init_params.close_on_deactivate = true; |
| 180 | 183 |
| 181 DCHECK(tray_container()); | 184 DCHECK(tray_container()); |
| 182 | 185 |
| 183 // Create view, customize it. | 186 // Create view, customize it. |
| 184 views::TrayBubbleView* bubble_view = | 187 views::TrayBubbleView* bubble_view = |
| 185 views::TrayBubbleView::Create(tray_container(), this, &init_params); | 188 views::TrayBubbleView::Create(tray_container(), this, &init_params); |
| 186 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | 189 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
| 187 bubble_view->UseCompactMargins(); | 190 bubble_view->UseCompactMargins(); |
| 188 bubble_view->set_margins(gfx::Insets(bubble_view->margins().top(), 0, 0, 0)); | 191 bubble_view->set_margins(gfx::Insets(bubble_view->margins().top(), 0, 0, 0)); |
| 189 | 192 |
| 190 // Add child views. | 193 // Add child views. |
| 191 bubble_view->AddChildView(new TitleView(this)); | 194 bubble_view->AddChildView(new TitleView(this)); |
| 192 bubble_view->AddChildView(CreateSeparator(views::Separator::HORIZONTAL)); | 195 bubble_view->AddChildView(CreateSeparator(views::Separator::HORIZONTAL)); |
| 193 AddToolsToView(bubble_view); | 196 AddToolsToView(bubble_view); |
| 194 | 197 |
| 195 // Show the bubble. | 198 // Show the bubble. |
| 196 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view)); | 199 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view)); |
| 197 | 200 |
| 198 SetDrawBackgroundAsActive(true); | 201 SetDrawBackgroundAsActive(true); |
| 199 | |
| 200 return true; | 202 return true; |
| 201 } | 203 } |
| 202 | 204 |
| 203 void PaletteTray::AddToolsToView(views::View* host) { | 205 void PaletteTray::AddToolsToView(views::View* host) { |
| 204 std::vector<PaletteToolView> views = palette_tool_manager_->CreateViews(); | 206 std::vector<PaletteToolView> views = palette_tool_manager_->CreateViews(); |
| 205 | 207 |
| 206 // There may not be any registered tools. | 208 // There may not be any registered tools. |
| 207 if (!views.size()) | 209 if (!views.size()) |
| 208 return; | 210 return; |
| 209 | 211 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 gfx::VectorIconId icon = palette_tool_manager_->GetActiveTrayIcon( | 330 gfx::VectorIconId icon = palette_tool_manager_->GetActiveTrayIcon( |
| 329 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)); | 331 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)); |
| 330 icon_->SetImage(CreateVectorIcon(icon, kShelfIconSize, kShelfIconColor)); | 332 icon_->SetImage(CreateVectorIcon(icon, kShelfIconSize, kShelfIconColor)); |
| 331 } | 333 } |
| 332 | 334 |
| 333 void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) { | 335 void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) { |
| 334 if (!WmShell::Get()->palette_delegate()->ShouldAutoOpenPalette()) | 336 if (!WmShell::Get()->palette_delegate()->ShouldAutoOpenPalette()) |
| 335 return; | 337 return; |
| 336 | 338 |
| 337 if (stylus_state == ui::StylusState::REMOVED && !bubble_) | 339 if (stylus_state == ui::StylusState::REMOVED && !bubble_) |
| 338 OpenBubble(); | 340 ShowPalette(); |
| 339 else if (stylus_state == ui::StylusState::INSERTED && bubble_) | 341 else if (stylus_state == ui::StylusState::INSERTED && bubble_) |
| 340 bubble_.reset(); | 342 bubble_.reset(); |
| 341 } | 343 } |
| 342 | 344 |
| 343 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { | 345 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { |
| 344 if (!enabled) | 346 if (!enabled) |
| 345 SetVisible(false); | 347 SetVisible(false); |
| 346 else | 348 else |
| 347 UpdateIconVisibility(); | 349 UpdateIconVisibility(); |
| 348 } | 350 } |
| 349 | 351 |
| 350 void PaletteTray::UpdateIconVisibility() { | 352 void PaletteTray::UpdateIconVisibility() { |
| 351 SessionStateDelegate* session_state_delegate = | 353 SessionStateDelegate* session_state_delegate = |
| 352 WmShell::Get()->GetSessionStateDelegate(); | 354 WmShell::Get()->GetSessionStateDelegate(); |
| 353 | 355 |
| 354 SetVisible(!session_state_delegate->IsScreenLocked() && | 356 SetVisible(!session_state_delegate->IsScreenLocked() && |
| 355 session_state_delegate->GetSessionState() == | 357 session_state_delegate->GetSessionState() == |
| 356 SessionStateDelegate::SESSION_STATE_ACTIVE && | 358 SessionStateDelegate::SESSION_STATE_ACTIVE && |
| 357 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != | 359 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != |
| 358 LoginStatus::KIOSK_APP); | 360 LoginStatus::KIOSK_APP); |
| 359 } | 361 } |
| 360 | 362 |
| 361 } // namespace ash | 363 } // namespace ash |
| OLD | NEW |