| 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/system/palette/palette_tray.h" | 5 #include "ash/system/palette/palette_tray.h" |
| 6 | 6 |
| 7 #include "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
| 8 #include "ash/accessibility_delegate.h" | 8 #include "ash/accessibility_delegate.h" |
| 9 #include "ash/resources/vector_icons/vector_icons.h" | 9 #include "ash/resources/vector_icons/vector_icons.h" |
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 156 } |
| 157 | 157 |
| 158 PaletteTray::~PaletteTray() { | 158 PaletteTray::~PaletteTray() { |
| 159 if (bubble_) | 159 if (bubble_) |
| 160 bubble_->bubble_view()->ResetDelegate(); | 160 bubble_->bubble_view()->ResetDelegate(); |
| 161 | 161 |
| 162 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); | 162 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); |
| 163 Shell::Get()->RemoveShellObserver(this); | 163 Shell::Get()->RemoveShellObserver(this); |
| 164 } | 164 } |
| 165 | 165 |
| 166 bool PaletteTray::PerformAction(const ui::Event& event) { | |
| 167 if (bubble_) { | |
| 168 if (num_actions_in_bubble_ == 0) | |
| 169 RecordPaletteOptionsUsage(PaletteTrayOptions::PALETTE_CLOSED_NO_ACTION); | |
| 170 HidePalette(); | |
| 171 return true; | |
| 172 } | |
| 173 | |
| 174 return ShowPalette(); | |
| 175 } | |
| 176 | |
| 177 bool PaletteTray::ShowPalette() { | |
| 178 if (bubble_) | |
| 179 return false; | |
| 180 | |
| 181 DCHECK(tray_container()); | |
| 182 | |
| 183 views::TrayBubbleView::InitParams init_params; | |
| 184 init_params.delegate = this; | |
| 185 init_params.parent_window = GetBubbleWindowContainer(); | |
| 186 init_params.anchor_view = GetBubbleAnchor(); | |
| 187 init_params.anchor_alignment = GetAnchorAlignment(); | |
| 188 init_params.min_width = kPaletteWidth; | |
| 189 init_params.max_width = kPaletteWidth; | |
| 190 init_params.close_on_deactivate = true; | |
| 191 | |
| 192 // TODO(tdanderson): Refactor into common row layout code. | |
| 193 // TODO(tdanderson|jdufault): Add material design ripple effects to the menu | |
| 194 // rows. | |
| 195 | |
| 196 // Create and customize bubble view. | |
| 197 views::TrayBubbleView* bubble_view = new views::TrayBubbleView(init_params); | |
| 198 bubble_view->set_anchor_view_insets(GetBubbleAnchorInsets()); | |
| 199 bubble_view->set_margins( | |
| 200 gfx::Insets(kPalettePaddingOnTop, 0, kPalettePaddingOnBottom, 0)); | |
| 201 | |
| 202 // Add title. | |
| 203 auto* title_view = new TitleView(this); | |
| 204 title_view->SetBorder(views::CreateEmptyBorder( | |
| 205 gfx::Insets(0, kPaddingBetweenTitleAndLeftEdge, 0, 0))); | |
| 206 bubble_view->AddChildView(title_view); | |
| 207 | |
| 208 // Add horizontal separator. | |
| 209 views::Separator* separator = new views::Separator(); | |
| 210 separator->SetColor(kPaletteSeparatorColor); | |
| 211 separator->SetBorder(views::CreateEmptyBorder(gfx::Insets( | |
| 212 kPaddingBetweenTitleAndSeparator, 0, kMenuSeparatorVerticalPadding, 0))); | |
| 213 bubble_view->AddChildView(separator); | |
| 214 | |
| 215 // Add palette tools. | |
| 216 // TODO(tdanderson|jdufault): Use SystemMenuButton to get the material design | |
| 217 // ripples. | |
| 218 std::vector<PaletteToolView> views = palette_tool_manager_->CreateViews(); | |
| 219 for (const PaletteToolView& view : views) | |
| 220 bubble_view->AddChildView(view.view); | |
| 221 | |
| 222 // Show the bubble. | |
| 223 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view)); | |
| 224 SetIsActive(true); | |
| 225 return true; | |
| 226 } | |
| 227 | |
| 228 bool PaletteTray::ContainsPointInScreen(const gfx::Point& point) { | 166 bool PaletteTray::ContainsPointInScreen(const gfx::Point& point) { |
| 229 if (icon_ && icon_->GetBoundsInScreen().Contains(point)) | 167 if (icon_ && icon_->GetBoundsInScreen().Contains(point)) |
| 230 return true; | 168 return true; |
| 231 | 169 |
| 232 return bubble_ && bubble_->bubble_view()->GetBoundsInScreen().Contains(point); | 170 return bubble_ && bubble_->bubble_view()->GetBoundsInScreen().Contains(point); |
| 233 } | 171 } |
| 234 | 172 |
| 235 void PaletteTray::OnSessionStateChanged(session_manager::SessionState state) { | 173 void PaletteTray::OnSessionStateChanged(session_manager::SessionState state) { |
| 236 UpdateIconVisibility(); | 174 UpdateIconVisibility(); |
| 237 } | 175 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 211 |
| 274 // Don't do anything if the palette should not be shown or if the user has | 212 // Don't do anything if the palette should not be shown or if the user has |
| 275 // disabled it all-together. | 213 // disabled it all-together. |
| 276 if (!IsInUserSession() || !palette_delegate->ShouldShowPalette()) | 214 if (!IsInUserSession() || !palette_delegate->ShouldShowPalette()) |
| 277 return; | 215 return; |
| 278 | 216 |
| 279 // Auto show/hide the palette if allowed by the user. | 217 // Auto show/hide the palette if allowed by the user. |
| 280 if (palette_delegate->ShouldAutoOpenPalette()) { | 218 if (palette_delegate->ShouldAutoOpenPalette()) { |
| 281 if (stylus_state == ui::StylusState::REMOVED && !bubble_) { | 219 if (stylus_state == ui::StylusState::REMOVED && !bubble_) { |
| 282 is_bubble_auto_opened_ = true; | 220 is_bubble_auto_opened_ = true; |
| 283 ShowPalette(); | 221 ShowBubble(); |
| 284 } else if (stylus_state == ui::StylusState::INSERTED && bubble_) { | 222 } else if (stylus_state == ui::StylusState::INSERTED && bubble_) { |
| 285 HidePalette(); | 223 HidePalette(); |
| 286 } | 224 } |
| 287 } | 225 } |
| 288 | 226 |
| 289 // Disable any active modes if the stylus has been inserted. | 227 // Disable any active modes if the stylus has been inserted. |
| 290 if (stylus_state == ui::StylusState::INSERTED) | 228 if (stylus_state == ui::StylusState::INSERTED) |
| 291 palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE); | 229 palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE); |
| 292 } | 230 } |
| 293 | 231 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 // |delegate| can be null in tests. | 316 // |delegate| can be null in tests. |
| 379 if (!delegate) | 317 if (!delegate) |
| 380 return; | 318 return; |
| 381 | 319 |
| 382 // OnPaletteEnabledPrefChanged will get called with the initial pref value, | 320 // OnPaletteEnabledPrefChanged will get called with the initial pref value, |
| 383 // which will take care of showing the palette. | 321 // which will take care of showing the palette. |
| 384 palette_enabled_subscription_ = delegate->AddPaletteEnableListener(base::Bind( | 322 palette_enabled_subscription_ = delegate->AddPaletteEnableListener(base::Bind( |
| 385 &PaletteTray::OnPaletteEnabledPrefChanged, weak_factory_.GetWeakPtr())); | 323 &PaletteTray::OnPaletteEnabledPrefChanged, weak_factory_.GetWeakPtr())); |
| 386 } | 324 } |
| 387 | 325 |
| 326 bool PaletteTray::PerformAction(const ui::Event& event) { |
| 327 if (bubble_) { |
| 328 if (num_actions_in_bubble_ == 0) |
| 329 RecordPaletteOptionsUsage(PaletteTrayOptions::PALETTE_CLOSED_NO_ACTION); |
| 330 HidePalette(); |
| 331 return true; |
| 332 } |
| 333 |
| 334 ShowBubble(); |
| 335 return true; |
| 336 } |
| 337 |
| 338 void PaletteTray::CloseBubble() { |
| 339 HidePalette(); |
| 340 } |
| 341 |
| 342 void PaletteTray::ShowBubble() { |
| 343 if (bubble_) |
| 344 return; |
| 345 |
| 346 DCHECK(tray_container()); |
| 347 |
| 348 views::TrayBubbleView::InitParams init_params; |
| 349 init_params.delegate = this; |
| 350 init_params.parent_window = GetBubbleWindowContainer(); |
| 351 init_params.anchor_view = GetBubbleAnchor(); |
| 352 init_params.anchor_alignment = GetAnchorAlignment(); |
| 353 init_params.min_width = kPaletteWidth; |
| 354 init_params.max_width = kPaletteWidth; |
| 355 init_params.close_on_deactivate = true; |
| 356 |
| 357 // TODO(tdanderson): Refactor into common row layout code. |
| 358 // TODO(tdanderson|jdufault): Add material design ripple effects to the menu |
| 359 // rows. |
| 360 |
| 361 // Create and customize bubble view. |
| 362 views::TrayBubbleView* bubble_view = new views::TrayBubbleView(init_params); |
| 363 bubble_view->set_anchor_view_insets(GetBubbleAnchorInsets()); |
| 364 bubble_view->set_margins( |
| 365 gfx::Insets(kPalettePaddingOnTop, 0, kPalettePaddingOnBottom, 0)); |
| 366 |
| 367 // Add title. |
| 368 auto* title_view = new TitleView(this); |
| 369 title_view->SetBorder(views::CreateEmptyBorder( |
| 370 gfx::Insets(0, kPaddingBetweenTitleAndLeftEdge, 0, 0))); |
| 371 bubble_view->AddChildView(title_view); |
| 372 |
| 373 // Add horizontal separator. |
| 374 views::Separator* separator = new views::Separator(); |
| 375 separator->SetColor(kPaletteSeparatorColor); |
| 376 separator->SetBorder(views::CreateEmptyBorder(gfx::Insets( |
| 377 kPaddingBetweenTitleAndSeparator, 0, kMenuSeparatorVerticalPadding, 0))); |
| 378 bubble_view->AddChildView(separator); |
| 379 |
| 380 // Add palette tools. |
| 381 // TODO(tdanderson|jdufault): Use SystemMenuButton to get the material design |
| 382 // ripples. |
| 383 std::vector<PaletteToolView> views = palette_tool_manager_->CreateViews(); |
| 384 for (const PaletteToolView& view : views) |
| 385 bubble_view->AddChildView(view.view); |
| 386 |
| 387 // Show the bubble. |
| 388 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view)); |
| 389 SetIsActive(true); |
| 390 } |
| 391 |
| 392 views::TrayBubbleView* PaletteTray::GetBubbleView() { |
| 393 return bubble_ ? bubble_->bubble_view() : nullptr; |
| 394 } |
| 395 |
| 388 void PaletteTray::UpdateTrayIcon() { | 396 void PaletteTray::UpdateTrayIcon() { |
| 389 icon_->SetImage(CreateVectorIcon( | 397 icon_->SetImage(CreateVectorIcon( |
| 390 palette_tool_manager_->GetActiveTrayIcon( | 398 palette_tool_manager_->GetActiveTrayIcon( |
| 391 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)), | 399 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)), |
| 392 kTrayIconSize, kShelfIconColor)); | 400 kTrayIconSize, kShelfIconColor)); |
| 393 } | 401 } |
| 394 | 402 |
| 395 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { | 403 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { |
| 396 is_palette_enabled_ = enabled; | 404 is_palette_enabled_ = enabled; |
| 397 | 405 |
| 398 if (!enabled) { | 406 if (!enabled) { |
| 399 SetVisible(false); | 407 SetVisible(false); |
| 400 palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE); | 408 palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE); |
| 401 } else { | 409 } else { |
| 402 UpdateIconVisibility(); | 410 UpdateIconVisibility(); |
| 403 } | 411 } |
| 404 } | 412 } |
| 405 | 413 |
| 406 void PaletteTray::UpdateIconVisibility() { | 414 void PaletteTray::UpdateIconVisibility() { |
| 407 SetVisible(is_palette_enabled_ && palette_utils::HasStylusInput() && | 415 SetVisible(is_palette_enabled_ && palette_utils::HasStylusInput() && |
| 408 ShouldShowOnDisplay(this) && IsInUserSession()); | 416 ShouldShowOnDisplay(this) && IsInUserSession()); |
| 409 } | 417 } |
| 410 | 418 |
| 411 } // namespace ash | 419 } // namespace ash |
| OLD | NEW |