OLD | NEW |
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" | 10 #include "ui/base/resource/resource_bundle.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 // The view to guarantee the 48px height and place the contents at the | 42 // The view to guarantee the 48px height and place the contents at the |
43 // middle. It also guarantee the left margin. | 43 // middle. It also guarantee the left margin. |
44 class EntryView : public views::View { | 44 class EntryView : public views::View { |
45 public: | 45 public: |
46 EntryView(views::View* contents); | 46 EntryView(views::View* contents); |
47 virtual ~EntryView(); | 47 virtual ~EntryView(); |
48 | 48 |
49 // Overridden from views::View: | 49 // Overridden from views::View: |
50 virtual void Layout() OVERRIDE; | 50 virtual void Layout() OVERRIDE; |
51 virtual gfx::Size GetPreferredSize() OVERRIDE; | 51 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 52 virtual void OnFocus() OVERRIDE; |
52 | 53 |
53 private: | 54 private: |
54 DISALLOW_COPY_AND_ASSIGN(EntryView); | 55 DISALLOW_COPY_AND_ASSIGN(EntryView); |
55 }; | 56 }; |
56 | 57 |
57 EntryView::EntryView(views::View* contents) { | 58 EntryView::EntryView(views::View* contents) { |
58 AddChildView(contents); | 59 AddChildView(contents); |
59 } | 60 } |
60 | 61 |
61 EntryView::~EntryView() { | 62 EntryView::~EntryView() { |
62 } | 63 } |
63 | 64 |
64 void EntryView::Layout() { | 65 void EntryView::Layout() { |
65 DCHECK_EQ(1, child_count()); | 66 DCHECK_EQ(1, child_count()); |
66 views::View* contents = child_at(0); | 67 views::View* content = child_at(0); |
67 gfx::Size size = contents->GetPreferredSize(); | 68 int content_width = width() - kMarginWidth * 2; |
68 int y = 0; | 69 int content_height = content->GetHeightForWidth(content_width); |
69 if (size.height() < height()) | 70 int y = std::max((height() - content_height) / 2, 0); |
70 y = (height() - size.height()) / 2; | 71 content->SetBounds(kMarginWidth, y, content_width, content_height); |
71 contents->SetBounds(kMarginWidth, y, width() - kMarginWidth, size.height()); | |
72 } | 72 } |
73 | 73 |
74 gfx::Size EntryView::GetPreferredSize() { | 74 gfx::Size EntryView::GetPreferredSize() { |
75 DCHECK_EQ(1, child_count()); | 75 DCHECK_EQ(1, child_count()); |
76 gfx::Size size = child_at(0)->GetPreferredSize(); | 76 gfx::Size size = child_at(0)->GetPreferredSize(); |
77 size.ClampToMin(gfx::Size(kMinimumWindowWidth, kEntryHeight)); | 77 size.ClampToMin(gfx::Size(kMinimumWindowWidth, kEntryHeight)); |
78 return size; | 78 return size; |
79 } | 79 } |
80 | 80 |
| 81 void EntryView::OnFocus() { |
| 82 ScrollRectToVisible(GetLocalBounds()); |
| 83 } |
| 84 |
81 // The separator line between the title and the scroll view. Currently | 85 // The separator line between the title and the scroll view. Currently |
82 // it is achieved as a top border of the scroll view. | 86 // it is achieved as a top border of the scroll view. |
83 class Separator : public views::Border { | 87 class Separator : public views::Border { |
84 public: | 88 public: |
85 Separator(); | 89 Separator(); |
86 virtual ~Separator(); | 90 virtual ~Separator(); |
87 | 91 |
88 // Overridden from views::Border: | 92 // Overridden from views::Border: |
89 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE; | 93 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE; |
90 virtual gfx::Insets GetInsets() const OVERRIDE; | 94 virtual gfx::Insets GetInsets() const OVERRIDE; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 NotifierButton(Notifier* notifier, views::ButtonListener* listener) | 138 NotifierButton(Notifier* notifier, views::ButtonListener* listener) |
135 : views::CustomButton(listener), | 139 : views::CustomButton(listener), |
136 notifier_(notifier), | 140 notifier_(notifier), |
137 icon_view_(NULL), | 141 icon_view_(NULL), |
138 checkbox_(new views::Checkbox(string16())) { | 142 checkbox_(new views::Checkbox(string16())) { |
139 DCHECK(notifier); | 143 DCHECK(notifier); |
140 SetLayoutManager(new views::BoxLayout( | 144 SetLayoutManager(new views::BoxLayout( |
141 views::BoxLayout::kHorizontal, 0, 0, kSpaceInButtonComponents)); | 145 views::BoxLayout::kHorizontal, 0, 0, kSpaceInButtonComponents)); |
142 checkbox_->SetChecked(notifier_->enabled); | 146 checkbox_->SetChecked(notifier_->enabled); |
143 checkbox_->set_listener(this); | 147 checkbox_->set_listener(this); |
144 checkbox_->set_focusable(true); | |
145 AddChildView(checkbox_); | 148 AddChildView(checkbox_); |
146 UpdateIconImage(notifier_->icon); | 149 UpdateIconImage(notifier_->icon); |
147 AddChildView(new views::Label(notifier_->name)); | 150 AddChildView(new views::Label(notifier_->name)); |
148 } | 151 } |
149 | 152 |
150 void UpdateIconImage(const gfx::Image& icon) { | 153 void UpdateIconImage(const gfx::Image& icon) { |
151 notifier_->icon = icon; | 154 notifier_->icon = icon; |
152 if (icon.IsEmpty()) { | 155 if (icon.IsEmpty()) { |
153 delete icon_view_; | 156 delete icon_view_; |
154 icon_view_ = NULL; | 157 icon_view_ = NULL; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 AddChildView(scroller_); | 260 AddChildView(scroller_); |
258 | 261 |
259 views::View* contents_view = new views::View(); | 262 views::View* contents_view = new views::View(); |
260 contents_view->SetLayoutManager(new views::BoxLayout( | 263 contents_view->SetLayoutManager(new views::BoxLayout( |
261 views::BoxLayout::kVertical, 0, 0, 0)); | 264 views::BoxLayout::kVertical, 0, 0, 0)); |
262 | 265 |
263 views::Label* top_label = new views::Label(l10n_util::GetStringUTF16( | 266 views::Label* top_label = new views::Label(l10n_util::GetStringUTF16( |
264 IDS_MESSAGE_CENTER_SETTINGS_DIALOG_DESCRIPTION)); | 267 IDS_MESSAGE_CENTER_SETTINGS_DIALOG_DESCRIPTION)); |
265 top_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 268 top_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
266 top_label->SetMultiLine(true); | 269 top_label->SetMultiLine(true); |
267 top_label->SizeToFit(kMinimumWindowWidth - kMarginWidth); | 270 top_label->SizeToFit(kMinimumWindowWidth - kMarginWidth * 2); |
268 contents_view->AddChildView(new EntryView(top_label)); | 271 contents_view->AddChildView(new EntryView(top_label)); |
269 | 272 |
270 std::vector<Notifier*> notifiers; | 273 std::vector<Notifier*> notifiers; |
271 delegate_->GetNotifierList(¬ifiers); | 274 delegate_->GetNotifierList(¬ifiers); |
272 for (size_t i = 0; i < notifiers.size(); ++i) { | 275 for (size_t i = 0; i < notifiers.size(); ++i) { |
273 NotifierButton* button = new NotifierButton(notifiers[i], this); | 276 NotifierButton* button = new NotifierButton(notifiers[i], this); |
274 contents_view->AddChildView(new EntryView(button)); | 277 EntryView* entry = new EntryView(button); |
| 278 entry->set_focusable(true); |
| 279 contents_view->AddChildView(entry); |
275 buttons_.insert(button); | 280 buttons_.insert(button); |
276 } | 281 } |
277 scroller_->SetContents(contents_view); | 282 scroller_->SetContents(contents_view); |
278 | 283 |
279 contents_view->SetBoundsRect(gfx::Rect(contents_view->GetPreferredSize())); | 284 contents_view->SetBoundsRect(gfx::Rect(contents_view->GetPreferredSize())); |
280 } | 285 } |
281 | 286 |
282 NotifierSettingsView::~NotifierSettingsView() { | 287 NotifierSettingsView::~NotifierSettingsView() { |
283 settings_view_ = NULL; | 288 settings_view_ = NULL; |
284 } | 289 } |
285 | 290 |
286 void NotifierSettingsView::WindowClosing() { | 291 void NotifierSettingsView::WindowClosing() { |
287 if (delegate_) | 292 if (delegate_) |
288 delegate_->OnNotifierSettingsClosing(); | 293 delegate_->OnNotifierSettingsClosing(); |
289 } | 294 } |
290 | 295 |
291 views::View* NotifierSettingsView::GetContentsView() { | 296 views::View* NotifierSettingsView::GetContentsView() { |
292 return this; | 297 return this; |
293 } | 298 } |
294 | 299 |
295 bool NotifierSettingsView::CanResize() const { | 300 bool NotifierSettingsView::CanResize() const { |
296 return true; | 301 return true; |
297 } | 302 } |
298 | 303 |
299 void NotifierSettingsView::Layout() { | 304 void NotifierSettingsView::Layout() { |
300 int title_height = title_entry_->GetPreferredSize().height(); | 305 int title_height = title_entry_->GetPreferredSize().height(); |
301 title_entry_->SetBounds(0, 0, width(), title_height); | 306 title_entry_->SetBounds(0, 0, width(), title_height); |
| 307 views::View* contents_view = scroller_->contents(); |
| 308 int content_width = width(); |
| 309 int content_height = contents_view->GetHeightForWidth(content_width); |
| 310 if (title_height + content_height > kMinimumWindowHeight) { |
| 311 content_width -= scroller_->GetScrollBarWidth(); |
| 312 content_height = contents_view->GetHeightForWidth(content_width); |
| 313 } |
| 314 contents_view->SetBounds(0, 0, content_width, content_height); |
302 scroller_->SetBounds(0, title_height, width(), height() - title_height); | 315 scroller_->SetBounds(0, title_height, width(), height() - title_height); |
303 } | 316 } |
304 | 317 |
305 gfx::Size NotifierSettingsView::GetMinimumSize() { | 318 gfx::Size NotifierSettingsView::GetMinimumSize() { |
306 gfx::Size size(kMinimumWindowWidth, kMinimumWindowHeight); | 319 gfx::Size size(kMinimumWindowWidth, kMinimumWindowHeight); |
307 int total_height = title_entry_->GetPreferredSize().height() + | 320 int total_height = title_entry_->GetPreferredSize().height() + |
308 scroller_->contents()->GetPreferredSize().height(); | 321 scroller_->contents()->GetPreferredSize().height(); |
309 if (total_height > kMinimumWindowHeight) | 322 if (total_height > kMinimumWindowHeight) |
310 size.Enlarge(scroller_->GetScrollBarWidth(), 0); | 323 size.Enlarge(scroller_->GetScrollBarWidth(), 0); |
311 return size; | 324 return size; |
312 } | 325 } |
313 | 326 |
314 gfx::Size NotifierSettingsView::GetPreferredSize() { | 327 gfx::Size NotifierSettingsView::GetPreferredSize() { |
315 return GetMinimumSize(); | 328 return GetMinimumSize(); |
316 } | 329 } |
317 | 330 |
318 void NotifierSettingsView::ButtonPressed(views::Button* sender, | 331 void NotifierSettingsView::ButtonPressed(views::Button* sender, |
319 const ui::Event& event) { | 332 const ui::Event& event) { |
320 std::set<NotifierButton*>::iterator iter = buttons_.find( | 333 std::set<NotifierButton*>::iterator iter = buttons_.find( |
321 static_cast<NotifierButton*>(sender)); | 334 static_cast<NotifierButton*>(sender)); |
322 DCHECK(iter != buttons_.end()); | 335 DCHECK(iter != buttons_.end()); |
323 | 336 |
324 (*iter)->SetChecked(!(*iter)->checked()); | 337 (*iter)->SetChecked(!(*iter)->checked()); |
325 if (delegate_) | 338 if (delegate_) |
326 delegate_->SetNotifierEnabled((*iter)->notifier(), (*iter)->checked()); | 339 delegate_->SetNotifierEnabled((*iter)->notifier(), (*iter)->checked()); |
327 } | 340 } |
328 | 341 |
329 } // namespace message_center | 342 } // namespace message_center |
OLD | NEW |