| 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/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
| 8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
| 9 #include "ash/common/shelf/shelf_constants.h" | 9 #include "ash/common/shelf/shelf_constants.h" |
| 10 #include "ash/common/shelf/wm_shelf.h" | 10 #include "ash/common/shelf/wm_shelf.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 #include "ui/views/controls/separator.h" | 38 #include "ui/views/controls/separator.h" |
| 39 #include "ui/views/layout/box_layout.h" | 39 #include "ui/views/layout/box_layout.h" |
| 40 #include "ui/views/layout/fill_layout.h" | 40 #include "ui/views/layout/fill_layout.h" |
| 41 | 41 |
| 42 namespace ash { | 42 namespace ash { |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 // Predefined padding for the icon used in this tray. These are to be set to the | 46 // Predefined padding for the icon used in this tray. These are to be set to the |
| 47 // border of the icon, depending on the current |shelf_alignment()|. | 47 // border of the icon, depending on the current |shelf_alignment()|. |
| 48 const int kHorizontalShelfHorizontalPadding = 8; | 48 constexpr int kHorizontalShelfHorizontalPadding = 8; |
| 49 const int kHorizontalShelfVerticalPadding = 4; | 49 constexpr int kHorizontalShelfVerticalPadding = 4; |
| 50 const int kVerticalShelfHorizontalPadding = 2; | 50 constexpr int kVerticalShelfHorizontalPadding = 2; |
| 51 const int kVerticalShelfVerticalPadding = 5; | 51 constexpr int kVerticalShelfVerticalPadding = 5; |
| 52 | 52 |
| 53 // Width of the palette itself (dp). | 53 // Width of the palette itself (dp). |
| 54 const int kPaletteWidth = 332; | 54 constexpr int kPaletteWidth = 332; |
| 55 | 55 |
| 56 // Padding at the top/bottom of the palette (dp). | 56 // Padding at the top/bottom of the palette (dp). |
| 57 const int kPalettePaddingOnTop = 4; | 57 constexpr int kPalettePaddingOnTop = 4; |
| 58 const int kPalettePaddingOnBottom = 4; | 58 constexpr int kPalettePaddingOnBottom = 2; |
| 59 | |
| 60 // Size of icon in the shelf (dp). | |
| 61 const int kShelfIconSize = 18; | |
| 62 | |
| 63 // Vertical margin around the title view elements so that the title view height | |
| 64 // matches kMenuButtonSize. | |
| 65 const int kVerticalMarginAroundTitleView = 1; | |
| 66 | 59 |
| 67 // Margins between the title view and the edges around it (dp). | 60 // Margins between the title view and the edges around it (dp). |
| 68 const int kPaddingBetweenTitleAndLeftEdge = 12; | 61 constexpr int kPaddingBetweenTitleAndLeftEdge = 12; |
| 69 const int kPaddingBetweenTitleAndSeparator = 3; | 62 constexpr int kPaddingBetweenTitleAndSeparator = 3; |
| 70 | |
| 71 // The distance between the title, help, and settings button in the title (dp). | |
| 72 const int kHorizontalPaddingBetweenTitleEntries = 2; | |
| 73 | 63 |
| 74 // Color of the separator. | 64 // Color of the separator. |
| 75 const SkColor kPaletteSeparatorColor = SkColorSetARGB(0x1E, 0x00, 0x00, 0x00); | 65 const SkColor kPaletteSeparatorColor = SkColorSetARGB(0x1E, 0x00, 0x00, 0x00); |
| 76 | 66 |
| 77 // Returns true if we are in a user session that can show the stylus tools. | 67 // Returns true if we are in a user session that can show the stylus tools. |
| 78 bool IsInUserSession() { | 68 bool IsInUserSession() { |
| 79 SessionStateDelegate* session_state_delegate = | 69 SessionStateDelegate* session_state_delegate = |
| 80 WmShell::Get()->GetSessionStateDelegate(); | 70 WmShell::Get()->GetSessionStateDelegate(); |
| 81 return !session_state_delegate->IsUserSessionBlocked() && | 71 return !session_state_delegate->IsUserSessionBlocked() && |
| 82 session_state_delegate->GetSessionState() == | 72 session_state_delegate->GetSessionState() == |
| 83 session_manager::SessionState::ACTIVE && | 73 session_manager::SessionState::ACTIVE && |
| 84 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != | 74 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != |
| 85 LoginStatus::KIOSK_APP; | 75 LoginStatus::KIOSK_APP; |
| 86 } | 76 } |
| 87 | 77 |
| 88 class TitleView : public views::View, public views::ButtonListener { | 78 class TitleView : public views::View, public views::ButtonListener { |
| 89 public: | 79 public: |
| 90 explicit TitleView(PaletteTray* palette_tray) : palette_tray_(palette_tray) { | 80 explicit TitleView(PaletteTray* palette_tray) : palette_tray_(palette_tray) { |
| 91 // TODO(tdanderson|jdufault): Use TriView to handle the layout of the title. | 81 // TODO(tdanderson|jdufault): Use TriView to handle the layout of the title. |
| 92 // See crbug.com/614453. | 82 // See crbug.com/614453. |
| 93 auto* box_layout = new views::BoxLayout( | 83 auto* box_layout = |
| 94 views::BoxLayout::kHorizontal, 0, kVerticalMarginAroundTitleView, | 84 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); |
| 95 kHorizontalPaddingBetweenTitleEntries); | |
| 96 SetLayoutManager(box_layout); | 85 SetLayoutManager(box_layout); |
| 97 | 86 |
| 98 title_label_ = | 87 title_label_ = |
| 99 new views::Label(l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_TITLE)); | 88 new views::Label(l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_TITLE)); |
| 100 title_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 89 title_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 101 AddChildView(title_label_); | 90 AddChildView(title_label_); |
| 102 box_layout->SetFlexForView(title_label_, 1); | 91 box_layout->SetFlexForView(title_label_, 1); |
| 103 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 92 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 104 help_button_ = | 93 help_button_ = |
| 105 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, | 94 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 } else { | 413 } else { |
| 425 icon_->SetBorder(views::CreateEmptyBorder(gfx::Insets( | 414 icon_->SetBorder(views::CreateEmptyBorder(gfx::Insets( |
| 426 kVerticalShelfVerticalPadding, kVerticalShelfHorizontalPadding))); | 415 kVerticalShelfVerticalPadding, kVerticalShelfHorizontalPadding))); |
| 427 } | 416 } |
| 428 } | 417 } |
| 429 | 418 |
| 430 void PaletteTray::UpdateTrayIcon() { | 419 void PaletteTray::UpdateTrayIcon() { |
| 431 icon_->SetImage(CreateVectorIcon( | 420 icon_->SetImage(CreateVectorIcon( |
| 432 palette_tool_manager_->GetActiveTrayIcon( | 421 palette_tool_manager_->GetActiveTrayIcon( |
| 433 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)), | 422 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)), |
| 434 kShelfIconSize, kShelfIconColor)); | 423 kTrayIconSize, kShelfIconColor)); |
| 435 } | 424 } |
| 436 | 425 |
| 437 void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) { | 426 void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) { |
| 438 PaletteDelegate* palette_delegate = WmShell::Get()->palette_delegate(); | 427 PaletteDelegate* palette_delegate = WmShell::Get()->palette_delegate(); |
| 439 | 428 |
| 440 // Don't do anything if the palette should not be shown or if the user has | 429 // Don't do anything if the palette should not be shown or if the user has |
| 441 // disabled it all-together. | 430 // disabled it all-together. |
| 442 if (!IsInUserSession() || !palette_delegate->ShouldShowPalette()) | 431 if (!IsInUserSession() || !palette_delegate->ShouldShowPalette()) |
| 443 return; | 432 return; |
| 444 | 433 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 466 } else { | 455 } else { |
| 467 UpdateIconVisibility(); | 456 UpdateIconVisibility(); |
| 468 } | 457 } |
| 469 } | 458 } |
| 470 | 459 |
| 471 void PaletteTray::UpdateIconVisibility() { | 460 void PaletteTray::UpdateIconVisibility() { |
| 472 SetVisible(is_palette_enabled_ && IsInUserSession()); | 461 SetVisible(is_palette_enabled_ && IsInUserSession()); |
| 473 } | 462 } |
| 474 | 463 |
| 475 } // namespace ash | 464 } // namespace ash |
| OLD | NEW |