Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(504)

Side by Side Diff: ash/common/system/chromeos/palette/palette_tray.cc

Issue 2264383002: More closely align palette to spec. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tool-magnifier
Patch Set: Initial upload Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/gfx/color_palette.h"
25 #include "ui/gfx/paint_vector_icon.h" 26 #include "ui/gfx/paint_vector_icon.h"
27 #include "ui/gfx/vector_icons_public.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 {
35 37
36 // Predefined padding for the icon used in this tray. These are to be set to the 38 // Predefined padding for the icon used in this tray. These are to be set to the
37 // border of the icon, depending on the current |shelf_alignment()|. 39 // border of the icon, depending on the current |shelf_alignment()|.
38 const int kHorizontalShelfHorizontalPadding = 8; 40 const int kHorizontalShelfHorizontalPadding = 8;
39 const int kHorizontalShelfVerticalPadding = 4; 41 const int kHorizontalShelfVerticalPadding = 4;
40 const int kVerticalShelfHorizontalPadding = 2; 42 const int kVerticalShelfHorizontalPadding = 2;
41 const int kVerticalShelfVerticalPadding = 5; 43 const int kVerticalShelfVerticalPadding = 5;
42 44
43 // Width of the palette itself (dp). 45 // Width of the palette itself (dp).
44 const int kPaletteWidth = 360; 46 const int kPaletteWidth = 332;
45 47
46 // Size of icon in the shelf (dp). 48 // Size of icon in the shelf (dp).
47 const int kShelfIconSize = 18; 49 const int kShelfIconSize = 18;
48 50
51 // Margins between the title view and the edges around it (dp).
52 const int kPaddingBetweenTitleAndTopEdge = 4;
53 const int kPaddingBetweenTitleAndLeftEdge = 12;
54 const int kPaddingBetweenTitleAndSeparator = 3;
55
56 // Size of the header icons (dp).
57 const int kIconSize = 20;
58
49 // Creates a separator. 59 // Creates a separator.
50 views::Separator* CreateSeparator(views::Separator::Orientation orientation) { 60 views::Separator* CreateSeparator(views::Separator::Orientation orientation) {
51 const int kSeparatorInset = 10;
52
53 views::Separator* separator = 61 views::Separator* separator =
54 new views::Separator(views::Separator::HORIZONTAL); 62 new views::Separator(views::Separator::HORIZONTAL);
55 separator->SetColor(ash::kBorderDarkColor); 63 separator->SetColor(ash::kBorderDarkColor);
56 separator->SetBorder(
57 views::Border::CreateEmptyBorder(kSeparatorInset, 0, kSeparatorInset, 0));
58 return separator; 64 return separator;
59 } 65 }
60 66
61 class TitleView : public views::View, public views::ButtonListener { 67 class TitleView : public views::View, public views::ButtonListener {
62 public: 68 public:
63 explicit TitleView(PaletteTray* palette_tray) : palette_tray_(palette_tray) { 69 explicit TitleView(PaletteTray* palette_tray) : palette_tray_(palette_tray) {
64 auto& rb = ui::ResourceBundle::GetSharedInstance(); 70 auto& rb = ui::ResourceBundle::GetSharedInstance();
65 71
66 auto* box_layout = 72 auto* box_layout =
67 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); 73 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
68 SetLayoutManager(box_layout); 74 SetLayoutManager(box_layout);
69 SetBorder(views::Border::CreateEmptyBorder(
70 0, ash::kTrayPopupPaddingHorizontal, 0, 0));
71 75
72 views::Label* text_label = 76 views::Label* text_label =
73 new views::Label(l10n_util::GetStringUTF16(IDS_ASH_PALETTE_TITLE)); 77 new views::Label(l10n_util::GetStringUTF16(IDS_ASH_PALETTE_TITLE));
74 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 78 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
75 text_label->SetFontList(rb.GetFontList(ui::ResourceBundle::BoldFont)); 79 text_label->SetFontList(rb.GetFontList(ui::ResourceBundle::BoldFont));
76 AddChildView(text_label); 80 AddChildView(text_label);
77 box_layout->SetFlexForView(text_label, 1); 81 box_layout->SetFlexForView(text_label, 1);
78 82
79 help_button_ = new ash::TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_HELP, 83 gfx::ImageSkia settings_icon = CreateVectorIcon(
84 gfx::VectorIconId::SETTINGS, kIconSize, gfx::kChromeIconGrey);
85 // TODO: Add HELP icon
stevenjb 2016/08/24 15:58:57 TODO(jdufault)
jdufault 2016/08/24 18:48:06 Oops - I forgot to delete that before submitting :
86 gfx::ImageSkia help_icon = CreateVectorIcon(
87 gfx::VectorIconId::HELP, kIconSize, gfx::kChromeIconGrey);
88
89 help_button_ = new ash::TrayPopupHeaderButton(this, help_icon,
80 IDS_ASH_STATUS_TRAY_HELP); 90 IDS_ASH_STATUS_TRAY_HELP);
81 help_button_->SetTooltipText( 91 help_button_->SetTooltipText(
82 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SHUTDOWN)); 92 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_HELP));
83 AddChildView(help_button_); 93 AddChildView(help_button_);
84 94
85 AddChildView(CreateSeparator(views::Separator::VERTICAL));
86
87 settings_button_ = new ash::TrayPopupHeaderButton( 95 settings_button_ = new ash::TrayPopupHeaderButton(
88 this, IDR_AURA_UBER_TRAY_SETTINGS, IDS_ASH_STATUS_TRAY_SETTINGS); 96 this, settings_icon, IDS_ASH_STATUS_TRAY_SETTINGS);
89 settings_button_->SetTooltipText( 97 settings_button_->SetTooltipText(
90 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SETTINGS)); 98 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SETTINGS));
91 AddChildView(settings_button_); 99 AddChildView(settings_button_);
92 } 100 }
93 101
94 ~TitleView() override {} 102 ~TitleView() override {}
95 103
96 private: 104 private:
97 // views::ButtonListener: 105 // views::ButtonListener:
98 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 106 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 init_params.can_activate = true; 171 init_params.can_activate = true;
164 init_params.close_on_deactivate = true; 172 init_params.close_on_deactivate = true;
165 173
166 DCHECK(tray_container()); 174 DCHECK(tray_container());
167 175
168 // Create view, customize it. 176 // Create view, customize it.
169 views::TrayBubbleView* bubble_view = 177 views::TrayBubbleView* bubble_view =
170 views::TrayBubbleView::Create(tray_container(), this, &init_params); 178 views::TrayBubbleView::Create(tray_container(), this, &init_params);
171 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); 179 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
172 bubble_view->UseCompactMargins(); 180 bubble_view->UseCompactMargins();
173 bubble_view->set_margins(gfx::Insets(bubble_view->margins().top(), 0, 0, 0)); 181 bubble_view->set_margins(gfx::Insets(0, 0, 0, 0));
174 182
175 // Add child views. 183 // Add child views.
176 bubble_view->AddChildView(new TitleView(this)); 184 auto* title_view = new TitleView(this);
177 bubble_view->AddChildView(CreateSeparator(views::Separator::HORIZONTAL)); 185 title_view->SetBorder(views::Border::CreateEmptyBorder(gfx::Insets(
186 kPaddingBetweenTitleAndTopEdge, kPaddingBetweenTitleAndLeftEdge,
187 kPaddingBetweenTitleAndSeparator, 0)));
188 bubble_view->AddChildView(title_view);
189
190 auto* separator = CreateSeparator(views::Separator::HORIZONTAL);
stevenjb 2016/08/24 15:58:57 We generally avoid using auto* like this. It's all
jdufault 2016/08/24 18:48:06 Done.
191 separator->SetBorder(
192 views::Border::CreateEmptyBorder(gfx::Insets(0, 0, 4, 0)));
193 bubble_view->AddChildView(separator);
178 AddToolsToView(bubble_view); 194 AddToolsToView(bubble_view);
179 195
180 // Show the bubble. 196 // Show the bubble.
181 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view)); 197 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view));
182 198
183 SetDrawBackgroundAsActive(true); 199 SetDrawBackgroundAsActive(true);
184 200
185 return true; 201 return true;
186 } 202 }
187 203
188 void PaletteTray::AddToolsToView(views::View* host) { 204 void PaletteTray::AddToolsToView(views::View* host) {
189 std::vector<PaletteToolView> views = palette_tool_manager_->CreateViews(); 205 std::vector<PaletteToolView> views = palette_tool_manager_->CreateViews();
190 206 for (const PaletteToolView& view : views)
191 // There may not be any registered tools.
192 if (!views.size())
193 return;
194
195 PaletteGroup group = views[0].group;
196 for (const PaletteToolView& view : views) {
197 // If the group changes, add a separator.
198 if (group != view.group) {
199 group = view.group;
200 host->AddChildView(CreateSeparator(views::Separator::HORIZONTAL));
201 }
202
203 host->AddChildView(view.view); 207 host->AddChildView(view.view);
204 }
205 } 208 }
206 209
207 void PaletteTray::SessionStateChanged( 210 void PaletteTray::SessionStateChanged(
208 SessionStateDelegate::SessionState state) { 211 SessionStateDelegate::SessionState state) {
209 UpdateIconVisibility(); 212 UpdateIconVisibility();
210 } 213 }
211 214
212 void PaletteTray::ClickedOutsideBubble() { 215 void PaletteTray::ClickedOutsideBubble() {
213 HidePalette(); 216 HidePalette();
214 } 217 }
(...skipping 22 matching lines...) Expand all
237 240
238 gfx::Rect PaletteTray::GetAnchorRect( 241 gfx::Rect PaletteTray::GetAnchorRect(
239 views::Widget* anchor_widget, 242 views::Widget* anchor_widget,
240 views::TrayBubbleView::AnchorType anchor_type, 243 views::TrayBubbleView::AnchorType anchor_type,
241 views::TrayBubbleView::AnchorAlignment anchor_alignment) const { 244 views::TrayBubbleView::AnchorAlignment anchor_alignment) const {
242 gfx::Rect r = 245 gfx::Rect r =
243 GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); 246 GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment);
244 247
245 // Move the palette to the left so the right edge of the palette aligns with 248 // Move the palette to the left so the right edge of the palette aligns with
246 // the right edge of the tray button. 249 // the right edge of the tray button.
247 if (IsHorizontalAlignment(shelf_alignment())) 250 if (IsHorizontalAlignment(shelf_alignment())) {
248 r.Offset(-r.width() + tray_container()->width(), 0); 251 // TODO(jdufault): Figure out a more robust adjustment method that does not
249 else 252 // break in md-shelf.
253 int icon_size = tray_container()->width();
254 if (tray_container()->border())
255 icon_size -= tray_container()->border()->GetInsets().width();
256
257 r.Offset(-r.width() + icon_size, 0);
258 } else {
259 // Vertical layout doesn't need the border adjustment that horizontal needs.
250 r.Offset(0, -r.height() + tray_container()->height()); 260 r.Offset(0, -r.height() + tray_container()->height());
261 }
251 262
252 return r; 263 return r;
253 } 264 }
254 265
255 void PaletteTray::OnBeforeBubbleWidgetInit( 266 void PaletteTray::OnBeforeBubbleWidgetInit(
256 views::Widget* anchor_widget, 267 views::Widget* anchor_widget,
257 views::Widget* bubble_widget, 268 views::Widget* bubble_widget,
258 views::Widget::InitParams* params) const { 269 views::Widget::InitParams* params) const {
259 // Place the bubble in the same root window as |anchor_widget|. 270 // Place the bubble in the same root window as |anchor_widget|.
260 WmLookup::Get() 271 WmLookup::Get()
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 WmShell::Get()->GetSessionStateDelegate(); 330 WmShell::Get()->GetSessionStateDelegate();
320 331
321 SetVisible(!session_state_delegate->IsScreenLocked() && 332 SetVisible(!session_state_delegate->IsScreenLocked() &&
322 session_state_delegate->GetSessionState() == 333 session_state_delegate->GetSessionState() ==
323 SessionStateDelegate::SESSION_STATE_ACTIVE && 334 SessionStateDelegate::SESSION_STATE_ACTIVE &&
324 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != 335 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() !=
325 LoginStatus::KIOSK_APP); 336 LoginStatus::KIOSK_APP);
326 } 337 }
327 338
328 } // namespace ash 339 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698