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

Side by Side Diff: ash/system/status_area_widget_delegate.cc

Issue 10535112: Prepare status area to support multiple trays. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/status_area_widget_delegate.h" 5 #include "ash/system/status_area_widget_delegate.h"
6 6
7 #include "ash/ash_export.h" 7 #include "ash/ash_export.h"
8 #include "ash/focus_cycler.h" 8 #include "ash/focus_cycler.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "grit/ui_resources_standard.h" 12 #include "grit/ui_resources_standard.h"
13 #include "ui/aura/root_window.h" 13 #include "ui/aura/root_window.h"
14 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/gfx/canvas.h" 15 #include "ui/gfx/canvas.h"
16 #include "ui/gfx/image/image.h" 16 #include "ui/gfx/image/image.h"
17 #include "ui/views/accessible_pane_view.h" 17 #include "ui/views/accessible_pane_view.h"
18 #include "ui/views/layout/grid_layout.h"
18 #include "ui/views/widget/widget.h" 19 #include "ui/views/widget/widget.h"
19 20
20 namespace { 21 namespace {
21 22
22 int kTraySpacing = 10; 23 int kTraySpacing = 10;
23 24
24 } // namespace 25 } // namespace
25 26
26 namespace ash { 27 namespace ash {
27 namespace internal { 28 namespace internal {
28 29
29 StatusAreaWidgetDelegate::StatusAreaWidgetDelegate() 30 StatusAreaWidgetDelegate::StatusAreaWidgetDelegate()
30 : focus_cycler_for_testing_(NULL) { 31 : focus_cycler_for_testing_(NULL),
31 SetLayout(views::BoxLayout::kHorizontal); 32 alignment_(SHELF_ALIGNMENT_BOTTOM) {
32 } 33 }
33 34
34 StatusAreaWidgetDelegate::~StatusAreaWidgetDelegate() { 35 StatusAreaWidgetDelegate::~StatusAreaWidgetDelegate() {
35 } 36 }
36 37
37 void StatusAreaWidgetDelegate::SetFocusCyclerForTesting( 38 void StatusAreaWidgetDelegate::SetFocusCyclerForTesting(
38 const FocusCycler* focus_cycler) { 39 const FocusCycler* focus_cycler) {
39 focus_cycler_for_testing_ = focus_cycler; 40 focus_cycler_for_testing_ = focus_cycler;
40 } 41 }
41 42
(...skipping 23 matching lines...) Expand all
65 // We don't want mouse clicks to activate us, but we need to allow 66 // We don't want mouse clicks to activate us, but we need to allow
66 // activation when the user is using the keyboard (FocusCycler). 67 // activation when the user is using the keyboard (FocusCycler).
67 const FocusCycler* focus_cycler = focus_cycler_for_testing_ ? 68 const FocusCycler* focus_cycler = focus_cycler_for_testing_ ?
68 focus_cycler_for_testing_ : Shell::GetInstance()->focus_cycler(); 69 focus_cycler_for_testing_ : Shell::GetInstance()->focus_cycler();
69 return focus_cycler->widget_activating() == GetWidget(); 70 return focus_cycler->widget_activating() == GetWidget();
70 } 71 }
71 72
72 void StatusAreaWidgetDelegate::DeleteDelegate() { 73 void StatusAreaWidgetDelegate::DeleteDelegate() {
73 } 74 }
74 75
75 void StatusAreaWidgetDelegate::SetLayout( 76 void StatusAreaWidgetDelegate::AddTray(views::View* tray) {
76 views::BoxLayout::Orientation orientation) { 77 SetLayoutManager(NULL); // Reset layout manager before adding a child.
77 SetLayoutManager(new views::BoxLayout(orientation, 0, 0, kTraySpacing)); 78 AddChildView(tray);
79 // Set the layout manager with the new list of children.
80 UpdateLayout();
81 }
82
83 void StatusAreaWidgetDelegate::UpdateLayout() {
84 // Use a grid layout so that the trays can be centered in each cell, and
85 // so that the widget gets laid out correctly when tray sizes change.
sadrul 2012/06/12 15:13:39 I am not entirely sure we need grid-layout for thi
stevenjb 2012/06/12 16:46:50 I started with BoxLayout. The problem is that then
86 views::GridLayout* layout = new views::GridLayout(this);
87 SetLayoutManager(layout);
88
89 views::ColumnSet* columns = layout->AddColumnSet(0);
90 if (alignment_ == SHELF_ALIGNMENT_BOTTOM) {
91 for (int c = 0; c < child_count(); ++c) {
92 if (c != 0)
93 columns->AddPaddingColumn(0, kTraySpacing);
94 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER,
95 0, /* resize percent */
96 views::GridLayout::USE_PREF, 0, 0);
97 }
98 layout->StartRow(0, 0);
99 for (int c = 0; c < child_count(); ++c)
100 layout->AddView(child_at(c));
101 } else {
102 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER,
103 0, /* resize percent */
104 views::GridLayout::USE_PREF, 0, 0);
105 for (int c = 0; c < child_count(); ++c) {
106 if (c != 0)
107 layout->AddPaddingRow(0, kTraySpacing);
108 layout->StartRow(0, 0);
109 layout->AddView(child_at(c));
110 }
111 }
78 Layout(); 112 Layout();
79 } 113 }
80 114
115 void StatusAreaWidgetDelegate::ChildPreferredSizeChanged(View* child) {
116 // Need to re-layout the parent window when trays or items are added/removed.
117 parent()->GetWidget()->GetRootView()->Layout();
118 }
119
81 } // namespace internal 120 } // namespace internal
82 } // namespace ash 121 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698