| 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" |
| 11 #include "ash/common/system/chromeos/palette/palette_tool_manager.h" | 11 #include "ash/common/system/chromeos/palette/palette_tool_manager.h" |
| 12 #include "ash/common/system/chromeos/palette/palette_utils.h" | 12 #include "ash/common/system/chromeos/palette/palette_utils.h" |
| 13 #include "ash/common/system/tray/system_tray_delegate.h" | 13 #include "ash/common/system/tray/system_tray_delegate.h" |
| 14 #include "ash/common/system/tray/tray_bubble_wrapper.h" | 14 #include "ash/common/system/tray/tray_bubble_wrapper.h" |
| 15 #include "ash/common/system/tray/tray_constants.h" | 15 #include "ash/common/system/tray/tray_constants.h" |
| 16 #include "ash/common/system/tray/tray_popup_header_button.h" | 16 #include "ash/common/system/tray/tray_popup_header_button.h" |
| 17 #include "ash/common/wm_lookup.h" | 17 #include "ash/common/wm_lookup.h" |
| 18 #include "ash/common/wm_root_window_controller.h" | 18 #include "ash/common/wm_root_window_controller.h" |
| 19 #include "ash/common/wm_shell.h" | 19 #include "ash/common/wm_shell.h" |
| 20 #include "ash/common/wm_window.h" | 20 #include "ash/common/wm_window.h" |
| 21 #include "grit/ash_resources.h" | 21 #include "grit/ash_resources.h" |
| 22 #include "grit/ash_strings.h" | 22 #include "grit/ash_strings.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/events/devices/stylus_state.h" | 25 #include "ui/events/devices/stylus_state.h" |
| 26 #include "ui/gfx/color_palette.h" |
| 26 #include "ui/gfx/paint_vector_icon.h" | 27 #include "ui/gfx/paint_vector_icon.h" |
| 28 #include "ui/gfx/vector_icons_public.h" |
| 27 #include "ui/views/controls/image_view.h" | 29 #include "ui/views/controls/image_view.h" |
| 28 #include "ui/views/controls/label.h" | 30 #include "ui/views/controls/label.h" |
| 29 #include "ui/views/controls/separator.h" | 31 #include "ui/views/controls/separator.h" |
| 30 #include "ui/views/layout/box_layout.h" | 32 #include "ui/views/layout/box_layout.h" |
| 31 #include "ui/views/layout/fill_layout.h" | 33 #include "ui/views/layout/fill_layout.h" |
| 32 | 34 |
| 33 namespace ash { | 35 namespace ash { |
| 34 | 36 |
| 35 namespace { | 37 namespace { |
| 36 | 38 |
| 37 // Predefined padding for the icon used in this tray. These are to be set to the | 39 // Predefined padding for the icon used in this tray. These are to be set to the |
| 38 // border of the icon, depending on the current |shelf_alignment()|. | 40 // border of the icon, depending on the current |shelf_alignment()|. |
| 39 const int kHorizontalShelfHorizontalPadding = 8; | 41 const int kHorizontalShelfHorizontalPadding = 8; |
| 40 const int kHorizontalShelfVerticalPadding = 4; | 42 const int kHorizontalShelfVerticalPadding = 4; |
| 41 const int kVerticalShelfHorizontalPadding = 2; | 43 const int kVerticalShelfHorizontalPadding = 2; |
| 42 const int kVerticalShelfVerticalPadding = 5; | 44 const int kVerticalShelfVerticalPadding = 5; |
| 43 | 45 |
| 44 // Width of the palette itself (dp). | 46 // Width of the palette itself (dp). |
| 45 const int kPaletteWidth = 360; | 47 const int kPaletteWidth = 332; |
| 46 | 48 |
| 47 // Size of icon in the shelf (dp). | 49 // Size of icon in the shelf (dp). |
| 48 const int kShelfIconSize = 18; | 50 const int kShelfIconSize = 18; |
| 49 | 51 |
| 52 // Margins between the title view and the edges around it (dp). |
| 53 const int kPaddingBetweenTitleAndTopEdge = 4; |
| 54 const int kPaddingBetweenTitleAndLeftEdge = 12; |
| 55 const int kPaddingBetweenTitleAndSeparator = 3; |
| 56 |
| 57 // Margin between the separator beneath the title and the first action (dp). |
| 58 const int kPaddingActionsAndTopSeparator = 4; |
| 59 |
| 60 // Size of the header icons (dp). |
| 61 const int kIconSize = 20; |
| 62 |
| 50 // Creates a separator. | 63 // Creates a separator. |
| 51 views::Separator* CreateSeparator(views::Separator::Orientation orientation) { | 64 views::Separator* CreateSeparator(views::Separator::Orientation orientation) { |
| 52 const int kSeparatorInset = 10; | |
| 53 | |
| 54 views::Separator* separator = | 65 views::Separator* separator = |
| 55 new views::Separator(views::Separator::HORIZONTAL); | 66 new views::Separator(views::Separator::HORIZONTAL); |
| 56 separator->SetColor(ash::kBorderDarkColor); | 67 separator->SetColor(ash::kBorderDarkColor); |
| 57 separator->SetBorder( | |
| 58 views::Border::CreateEmptyBorder(kSeparatorInset, 0, kSeparatorInset, 0)); | |
| 59 return separator; | 68 return separator; |
| 60 } | 69 } |
| 61 | 70 |
| 62 class TitleView : public views::View, public views::ButtonListener { | 71 class TitleView : public views::View, public views::ButtonListener { |
| 63 public: | 72 public: |
| 64 explicit TitleView(PaletteTray* palette_tray) : palette_tray_(palette_tray) { | 73 explicit TitleView(PaletteTray* palette_tray) : palette_tray_(palette_tray) { |
| 65 auto& rb = ui::ResourceBundle::GetSharedInstance(); | 74 auto& rb = ui::ResourceBundle::GetSharedInstance(); |
| 66 | 75 |
| 67 auto* box_layout = | 76 auto* box_layout = |
| 68 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | 77 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); |
| 69 SetLayoutManager(box_layout); | 78 SetLayoutManager(box_layout); |
| 70 SetBorder(views::Border::CreateEmptyBorder( | |
| 71 0, ash::kTrayPopupPaddingHorizontal, 0, 0)); | |
| 72 | 79 |
| 73 views::Label* text_label = | 80 views::Label* text_label = |
| 74 new views::Label(l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_TITLE)); | 81 new views::Label(l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_TITLE)); |
| 75 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 82 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 76 text_label->SetFontList(rb.GetFontList(ui::ResourceBundle::BoldFont)); | 83 text_label->SetFontList(rb.GetFontList(ui::ResourceBundle::BoldFont)); |
| 77 AddChildView(text_label); | 84 AddChildView(text_label); |
| 78 box_layout->SetFlexForView(text_label, 1); | 85 box_layout->SetFlexForView(text_label, 1); |
| 79 | 86 |
| 80 help_button_ = new ash::TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_HELP, | 87 gfx::ImageSkia settings_icon = CreateVectorIcon( |
| 88 gfx::VectorIconId::SETTINGS, kIconSize, gfx::kChromeIconGrey); |
| 89 gfx::ImageSkia help_icon = CreateVectorIcon( |
| 90 gfx::VectorIconId::HELP, kIconSize, gfx::kChromeIconGrey); |
| 91 |
| 92 help_button_ = new ash::TrayPopupHeaderButton(this, help_icon, |
| 81 IDS_ASH_STATUS_TRAY_HELP); | 93 IDS_ASH_STATUS_TRAY_HELP); |
| 82 help_button_->SetTooltipText( | 94 help_button_->SetTooltipText( |
| 83 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_HELP)); | 95 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_HELP)); |
| 84 AddChildView(help_button_); | 96 AddChildView(help_button_); |
| 85 | 97 |
| 86 AddChildView(CreateSeparator(views::Separator::VERTICAL)); | |
| 87 | |
| 88 settings_button_ = new ash::TrayPopupHeaderButton( | 98 settings_button_ = new ash::TrayPopupHeaderButton( |
| 89 this, IDR_AURA_UBER_TRAY_SETTINGS, IDS_ASH_STATUS_TRAY_SETTINGS); | 99 this, settings_icon, IDS_ASH_STATUS_TRAY_SETTINGS); |
| 90 settings_button_->SetTooltipText( | 100 settings_button_->SetTooltipText( |
| 91 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SETTINGS)); | 101 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SETTINGS)); |
| 92 AddChildView(settings_button_); | 102 AddChildView(settings_button_); |
| 93 } | 103 } |
| 94 | 104 |
| 95 ~TitleView() override {} | 105 ~TitleView() override {} |
| 96 | 106 |
| 97 private: | 107 private: |
| 98 // views::ButtonListener: | 108 // views::ButtonListener: |
| 99 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 109 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 init_params.can_activate = true; | 188 init_params.can_activate = true; |
| 179 init_params.close_on_deactivate = true; | 189 init_params.close_on_deactivate = true; |
| 180 | 190 |
| 181 DCHECK(tray_container()); | 191 DCHECK(tray_container()); |
| 182 | 192 |
| 183 // Create view, customize it. | 193 // Create view, customize it. |
| 184 views::TrayBubbleView* bubble_view = | 194 views::TrayBubbleView* bubble_view = |
| 185 views::TrayBubbleView::Create(tray_container(), this, &init_params); | 195 views::TrayBubbleView::Create(tray_container(), this, &init_params); |
| 186 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | 196 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
| 187 bubble_view->UseCompactMargins(); | 197 bubble_view->UseCompactMargins(); |
| 188 bubble_view->set_margins(gfx::Insets(bubble_view->margins().top(), 0, 0, 0)); | 198 bubble_view->set_margins(gfx::Insets(0, 0, 0, 0)); |
| 189 | 199 |
| 190 // Add child views. | 200 // Add child views. |
| 191 bubble_view->AddChildView(new TitleView(this)); | 201 auto* title_view = new TitleView(this); |
| 192 bubble_view->AddChildView(CreateSeparator(views::Separator::HORIZONTAL)); | 202 title_view->SetBorder(views::Border::CreateEmptyBorder(gfx::Insets( |
| 203 kPaddingBetweenTitleAndTopEdge, kPaddingBetweenTitleAndLeftEdge, |
| 204 kPaddingBetweenTitleAndSeparator, 0))); |
| 205 bubble_view->AddChildView(title_view); |
| 206 |
| 207 views::Separator* separator = CreateSeparator(views::Separator::HORIZONTAL); |
| 208 separator->SetBorder(views::Border::CreateEmptyBorder( |
| 209 gfx::Insets(0, 0, kPaddingActionsAndTopSeparator, 0))); |
| 210 bubble_view->AddChildView(separator); |
| 193 AddToolsToView(bubble_view); | 211 AddToolsToView(bubble_view); |
| 194 | 212 |
| 195 // Show the bubble. | 213 // Show the bubble. |
| 196 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view)); | 214 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view)); |
| 197 | 215 |
| 198 SetDrawBackgroundAsActive(true); | 216 SetDrawBackgroundAsActive(true); |
| 199 | 217 |
| 200 return true; | 218 return true; |
| 201 } | 219 } |
| 202 | 220 |
| 203 void PaletteTray::AddToolsToView(views::View* host) { | 221 void PaletteTray::AddToolsToView(views::View* host) { |
| 204 std::vector<PaletteToolView> views = palette_tool_manager_->CreateViews(); | 222 std::vector<PaletteToolView> views = palette_tool_manager_->CreateViews(); |
| 205 | 223 for (const PaletteToolView& view : views) |
| 206 // There may not be any registered tools. | |
| 207 if (!views.size()) | |
| 208 return; | |
| 209 | |
| 210 PaletteGroup group = views[0].group; | |
| 211 for (const PaletteToolView& view : views) { | |
| 212 // If the group changes, add a separator. | |
| 213 if (group != view.group) { | |
| 214 group = view.group; | |
| 215 host->AddChildView(CreateSeparator(views::Separator::HORIZONTAL)); | |
| 216 } | |
| 217 | |
| 218 host->AddChildView(view.view); | 224 host->AddChildView(view.view); |
| 219 } | |
| 220 } | 225 } |
| 221 | 226 |
| 222 void PaletteTray::SessionStateChanged( | 227 void PaletteTray::SessionStateChanged( |
| 223 SessionStateDelegate::SessionState state) { | 228 SessionStateDelegate::SessionState state) { |
| 224 UpdateIconVisibility(); | 229 UpdateIconVisibility(); |
| 225 } | 230 } |
| 226 | 231 |
| 227 void PaletteTray::ClickedOutsideBubble() { | 232 void PaletteTray::ClickedOutsideBubble() { |
| 228 bubble_.reset(); | 233 bubble_.reset(); |
| 229 } | 234 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 252 | 257 |
| 253 gfx::Rect PaletteTray::GetAnchorRect( | 258 gfx::Rect PaletteTray::GetAnchorRect( |
| 254 views::Widget* anchor_widget, | 259 views::Widget* anchor_widget, |
| 255 views::TrayBubbleView::AnchorType anchor_type, | 260 views::TrayBubbleView::AnchorType anchor_type, |
| 256 views::TrayBubbleView::AnchorAlignment anchor_alignment) const { | 261 views::TrayBubbleView::AnchorAlignment anchor_alignment) const { |
| 257 gfx::Rect r = | 262 gfx::Rect r = |
| 258 GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); | 263 GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); |
| 259 | 264 |
| 260 // Move the palette to the left so the right edge of the palette aligns with | 265 // Move the palette to the left so the right edge of the palette aligns with |
| 261 // the right edge of the tray button. | 266 // the right edge of the tray button. |
| 262 if (IsHorizontalAlignment(shelf_alignment())) | 267 if (IsHorizontalAlignment(shelf_alignment())) { |
| 263 r.Offset(-r.width() + tray_container()->width(), 0); | 268 // TODO(jdufault): Figure out a more robust adjustment method that does not |
| 264 else | 269 // break in md-shelf. |
| 270 int icon_size = tray_container()->width(); |
| 271 if (tray_container()->border()) |
| 272 icon_size -= tray_container()->border()->GetInsets().width(); |
| 273 |
| 274 r.Offset(-r.width() + icon_size, 0); |
| 275 } else { |
| 276 // Vertical layout doesn't need the border adjustment that horizontal needs. |
| 265 r.Offset(0, -r.height() + tray_container()->height()); | 277 r.Offset(0, -r.height() + tray_container()->height()); |
| 278 } |
| 266 | 279 |
| 267 return r; | 280 return r; |
| 268 } | 281 } |
| 269 | 282 |
| 270 void PaletteTray::OnBeforeBubbleWidgetInit( | 283 void PaletteTray::OnBeforeBubbleWidgetInit( |
| 271 views::Widget* anchor_widget, | 284 views::Widget* anchor_widget, |
| 272 views::Widget* bubble_widget, | 285 views::Widget* bubble_widget, |
| 273 views::Widget::InitParams* params) const { | 286 views::Widget::InitParams* params) const { |
| 274 // Place the bubble in the same root window as |anchor_widget|. | 287 // Place the bubble in the same root window as |anchor_widget|. |
| 275 WmLookup::Get() | 288 WmLookup::Get() |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 WmShell::Get()->GetSessionStateDelegate(); | 365 WmShell::Get()->GetSessionStateDelegate(); |
| 353 | 366 |
| 354 SetVisible(!session_state_delegate->IsScreenLocked() && | 367 SetVisible(!session_state_delegate->IsScreenLocked() && |
| 355 session_state_delegate->GetSessionState() == | 368 session_state_delegate->GetSessionState() == |
| 356 SessionStateDelegate::SESSION_STATE_ACTIVE && | 369 SessionStateDelegate::SESSION_STATE_ACTIVE && |
| 357 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != | 370 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != |
| 358 LoginStatus::KIOSK_APP); | 371 LoginStatus::KIOSK_APP); |
| 359 } | 372 } |
| 360 | 373 |
| 361 } // namespace ash | 374 } // namespace ash |
| OLD | NEW |