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

Side by Side Diff: ui/message_center/views/notifier_settings_view.cc

Issue 12465011: Redesign notifier settings view. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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
« no previous file with comments | « ui/message_center/views/notifier_settings_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "ui/message_center/views/notifier_settings_view.h" 5 #include "ui/message_center/views/notifier_settings_view.h"
6 6
7 #include "grit/ui_strings.h" 7 #include "grit/ui_strings.h"
8 #include "third_party/skia/include/core/SkColor.h" 8 #include "third_party/skia/include/core/SkColor.h"
9 #include "ui/base/l10n/l10n_util.h" 9 #include "ui/base/l10n/l10n_util.h"
10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/image/image.h" 12 #include "ui/gfx/image/image.h"
11 #include "ui/gfx/size.h" 13 #include "ui/gfx/size.h"
12 #include "ui/message_center/message_center_constants.h" 14 #include "ui/message_center/message_center_constants.h"
13 #include "ui/views/background.h" 15 #include "ui/views/background.h"
14 #include "ui/views/border.h" 16 #include "ui/views/border.h"
15 #include "ui/views/controls/button/checkbox.h" 17 #include "ui/views/controls/button/checkbox.h"
16 #include "ui/views/controls/button/custom_button.h" 18 #include "ui/views/controls/button/custom_button.h"
17 #include "ui/views/controls/image_view.h" 19 #include "ui/views/controls/image_view.h"
18 #include "ui/views/controls/label.h" 20 #include "ui/views/controls/label.h"
21 #include "ui/views/controls/scroll_view.h"
22 #include "ui/views/controls/scrollbar/kennedy_scroll_bar.h"
19 #include "ui/views/layout/box_layout.h" 23 #include "ui/views/layout/box_layout.h"
20 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
21 25
22 #if defined(USE_AURA) 26 #if defined(USE_AURA)
23 #include "ui/aura/window.h" 27 #include "ui/aura/window.h"
24 #endif 28 #endif
25 29
26 namespace message_center { 30 namespace message_center {
27 namespace { 31 namespace {
28 32
29 const int kSpaceInButtonComponents = 16; 33 const int kSpaceInButtonComponents = 16;
30 const int kMarginWidth = 16; 34 const int kMarginWidth = 16;
35 const int kMinimumWindowWidth = 320;
36 const int kMinimumWindowHeight = 480;
37 const int kEntryHeight = kMinimumWindowHeight / 10;
38 const SkColor kSeparatorColor = SkColorSetRGB(0xcc, 0xcc, 0xcc);
31 39
32 NotifierSettingsView* settings_view_ = NULL; 40 NotifierSettingsView* settings_view_ = NULL;
33 41
42 // The view to guarantee the 48px height and place the contents at the
43 // middle. It also guarantee the left margin.
44 class EntryView : public views::View {
45 public:
46 EntryView(views::View* contents);
47 virtual ~EntryView();
48
49 // Overridden from views::View:
50 virtual void Layout() OVERRIDE;
51 virtual gfx::Size GetPreferredSize() OVERRIDE;
52
53 private:
54 DISALLOW_COPY_AND_ASSIGN(EntryView);
55 };
56
57 EntryView::EntryView(views::View* contents) {
58 AddChildView(contents);
59 }
60
61 EntryView::~EntryView() {
62 }
63
64 void EntryView::Layout() {
65 DCHECK_EQ(1, child_count());
66 views::View* contents = child_at(0);
67 gfx::Size size = contents->GetPreferredSize();
68 int y = 0;
69 if (size.height() < height())
70 y = (height() - size.height()) / 2;
71 contents->SetBounds(kMarginWidth, y, width() - kMarginWidth, size.height());
72 }
73
74 gfx::Size EntryView::GetPreferredSize() {
75 DCHECK_EQ(1, child_count());
76 gfx::Size size = child_at(0)->GetPreferredSize();
77 size.ClampToMin(gfx::Size(kMinimumWindowWidth, kEntryHeight));
78 return size;
79 }
80
81 // The separator line between the title and the scroll view. Currently
82 // it is achieved as a top border of the scroll view.
83 class Separator : public views::Border {
84 public:
85 Separator();
86 virtual ~Separator();
87
88 // Overridden from views::Border:
89 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE;
90 virtual gfx::Insets GetInsets() const OVERRIDE;
91
92 private:
93 DISALLOW_COPY_AND_ASSIGN(Separator);
94 };
95
96 Separator::Separator() {
97 }
98
99 Separator::~Separator() {
100 }
101
102 void Separator::Paint(const views::View& view, gfx::Canvas* canvas) {
103 gfx::Rect bounds(view.GetLocalBounds());
104 bounds.Inset(kMarginWidth, 0);
105 const views::ScrollView* scroll_view =
106 static_cast<const views::ScrollView*>(&view);
107 bounds.set_width(bounds.width() - scroll_view->GetScrollBarWidth());
108 canvas->DrawLine(bounds.origin(), bounds.top_right(), kSeparatorColor);
109 }
110
111 gfx::Insets Separator::GetInsets() const {
112 return gfx::Insets(1, 0, 0, 0);
113 }
114
34 } // namespace 115 } // namespace
35 116
36 NotifierSettingsDelegate* ShowSettings(NotifierSettingsProvider* provider, 117 NotifierSettingsDelegate* ShowSettings(NotifierSettingsProvider* provider,
37 gfx::NativeView context) { 118 gfx::NativeView context) {
38 if (!settings_view_) { 119 if (!settings_view_) {
39 settings_view_ = NotifierSettingsView::Create(provider, context); 120 settings_view_ = NotifierSettingsView::Create(provider, context);
40 } 121 }
41 return settings_view_; 122 return settings_view_;
42 } 123 }
43 124
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 return; 226 return;
146 } 227 }
147 } 228 }
148 } 229 }
149 230
150 NotifierSettingsView::NotifierSettingsView( 231 NotifierSettingsView::NotifierSettingsView(
151 NotifierSettingsProvider* delegate) 232 NotifierSettingsProvider* delegate)
152 : delegate_(delegate) { 233 : delegate_(delegate) {
153 DCHECK(delegate_); 234 DCHECK(delegate_);
154 235
155 SetLayoutManager(new views::BoxLayout(
156 views::BoxLayout::kVertical, kMarginWidth, kMarginWidth, kMarginWidth));
157 set_background(views::Background::CreateSolidBackground(SK_ColorWHITE)); 236 set_background(views::Background::CreateSolidBackground(SK_ColorWHITE));
158 237
159 views::Label* top_label = new views::Label( 238 gfx::Font title_font =
160 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_FOOTER_TITLE)); 239 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont);
240 views::Label* title_label = new views::Label(
241 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_SETTINGS_BUTTON_LABEL),
242 title_font);
243 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
244 title_label->SetMultiLine(true);
245 title_entry_ = new EntryView(title_label);
246 AddChildView(title_entry_);
247
248 scroller_ = new views::ScrollView();
249 scroller_->set_border(new Separator());
250 scroller_->SetVerticalScrollBar(new views::KennedyScrollBar(false));
251 AddChildView(scroller_);
252
253 views::View* contents_view = new views::View();
254 contents_view->SetLayoutManager(new views::BoxLayout(
255 views::BoxLayout::kVertical, 0, 0, 0));
256
257 views::Label* top_label = new views::Label(l10n_util::GetStringUTF16(
258 IDS_MESSAGE_CENTER_SETTINGS_DIALOG_DESCRIPTION));
161 top_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 259 top_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
162 AddChildView(top_label); 260 top_label->SetMultiLine(true);
163 261 top_label->SizeToFit(kMinimumWindowWidth - kMarginWidth);
164 views::View* items = new views::View(); 262 contents_view->AddChildView(new EntryView(top_label));
165 items->SetLayoutManager(new views::BoxLayout(
166 views::BoxLayout::kVertical, 0, 0, kMarginWidth));
167 items->set_border(views::Border::CreateEmptyBorder(0, kMarginWidth, 0, 0));
168 AddChildView(items);
169 263
170 std::vector<Notifier*> notifiers; 264 std::vector<Notifier*> notifiers;
171 delegate_->GetNotifierList(&notifiers); 265 delegate_->GetNotifierList(&notifiers);
172 for (size_t i = 0; i < notifiers.size(); ++i) { 266 for (size_t i = 0; i < notifiers.size(); ++i) {
173 NotifierButton* button = new NotifierButton(notifiers[i], this); 267 NotifierButton* button = new NotifierButton(notifiers[i], this);
174 items->AddChildView(button); 268 contents_view->AddChildView(new EntryView(button));
175 buttons_.insert(button); 269 buttons_.insert(button);
176 } 270 }
271 scroller_->SetContents(contents_view);
272
273 gfx::Size contents_size = contents_view->GetPreferredSize();
274 if (kMinimumWindowHeight <
275 title_entry_->GetPreferredSize().height() + contents_size.height()) {
276 contents_size.Enlarge(-scroller_->GetScrollBarWidth(), 0);
277 }
278 contents_view->SetBoundsRect(gfx::Rect(contents_size));
177 } 279 }
178 280
179 NotifierSettingsView::~NotifierSettingsView() { 281 NotifierSettingsView::~NotifierSettingsView() {
180 settings_view_ = NULL; 282 settings_view_ = NULL;
181 } 283 }
182 284
183 bool NotifierSettingsView::CanResize() const {
184 return true;
185 }
186
187 string16 NotifierSettingsView::GetWindowTitle() const {
188 return l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_SETTINGS_BUTTON_LABEL);
189 }
190
191 void NotifierSettingsView::WindowClosing() { 285 void NotifierSettingsView::WindowClosing() {
192 if (delegate_) 286 if (delegate_)
193 delegate_->OnNotifierSettingsClosing(); 287 delegate_->OnNotifierSettingsClosing();
194 } 288 }
195 289
196 views::View* NotifierSettingsView::GetContentsView() { 290 views::View* NotifierSettingsView::GetContentsView() {
197 return this; 291 return this;
198 } 292 }
199 293
294 void NotifierSettingsView::Layout() {
295 int title_height = title_entry_->GetPreferredSize().height();
296 title_entry_->SetBounds(0, 0, width(), title_height);
297 scroller_->SetBounds(0, title_height, width(), height() - title_height);
298 }
299
300 gfx::Size NotifierSettingsView::GetMinimumSize() {
301 return gfx::Size(kMinimumWindowWidth, kMinimumWindowHeight);
302 }
303
200 void NotifierSettingsView::ButtonPressed(views::Button* sender, 304 void NotifierSettingsView::ButtonPressed(views::Button* sender,
201 const ui::Event& event) { 305 const ui::Event& event) {
202 std::set<NotifierButton*>::iterator iter = buttons_.find( 306 std::set<NotifierButton*>::iterator iter = buttons_.find(
203 static_cast<NotifierButton*>(sender)); 307 static_cast<NotifierButton*>(sender));
204 DCHECK(iter != buttons_.end()); 308 DCHECK(iter != buttons_.end());
205 309
206 (*iter)->SetChecked(!(*iter)->checked()); 310 (*iter)->SetChecked(!(*iter)->checked());
207 if (delegate_) 311 if (delegate_)
208 delegate_->SetNotifierEnabled((*iter)->notifier(), (*iter)->checked()); 312 delegate_->SetNotifierEnabled((*iter)->notifier(), (*iter)->checked());
209 } 313 }
210 314
211 } // namespace message_center 315 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/notifier_settings_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698