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

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

Issue 14198004: Scrolls to the notification when focus moves to its buttons. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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/notification_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) 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 "ui/message_center/views/notification_view.h" 5 #include "ui/message_center/views/notification_view.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "grit/ui_resources.h" 9 #include "grit/ui_resources.h"
10 #include "ui/base/accessibility/accessible_view_state.h" 10 #include "ui/base/accessibility/accessible_view_state.h"
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 public: 217 public:
218 NotificationButton(views::ButtonListener* listener); 218 NotificationButton(views::ButtonListener* listener);
219 virtual ~NotificationButton(); 219 virtual ~NotificationButton();
220 220
221 void SetIcon(const gfx::ImageSkia& icon); 221 void SetIcon(const gfx::ImageSkia& icon);
222 void SetTitle(const string16& title); 222 void SetTitle(const string16& title);
223 223
224 // Overridden from views::View: 224 // Overridden from views::View:
225 virtual gfx::Size GetPreferredSize() OVERRIDE; 225 virtual gfx::Size GetPreferredSize() OVERRIDE;
226 virtual int GetHeightForWidth(int width) OVERRIDE; 226 virtual int GetHeightForWidth(int width) OVERRIDE;
227 virtual void OnFocus() OVERRIDE;
227 228
228 // Overridden from views::CustomButton: 229 // Overridden from views::CustomButton:
229 virtual void StateChanged() OVERRIDE; 230 virtual void StateChanged() OVERRIDE;
230 231
231 private: 232 private:
232 views::ImageView* icon_; 233 views::ImageView* icon_;
233 views::Label* title_; 234 views::Label* title_;
234 }; 235 };
235 236
236 NotificationButton::NotificationButton(views::ButtonListener* listener) 237 NotificationButton::NotificationButton(views::ButtonListener* listener)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } 282 }
282 283
283 gfx::Size NotificationButton::GetPreferredSize() { 284 gfx::Size NotificationButton::GetPreferredSize() {
284 return gfx::Size(message_center::kNotificationWidth, kButtonHeight); 285 return gfx::Size(message_center::kNotificationWidth, kButtonHeight);
285 } 286 }
286 287
287 int NotificationButton::GetHeightForWidth(int width) { 288 int NotificationButton::GetHeightForWidth(int width) {
288 return kButtonHeight; 289 return kButtonHeight;
289 } 290 }
290 291
292 void NotificationButton::OnFocus() {
293 ScrollRectToVisible(GetLocalBounds());
294 }
295
291 void NotificationButton::StateChanged() { 296 void NotificationButton::StateChanged() {
292 if (state() == STATE_HOVERED || state() == STATE_PRESSED) 297 if (state() == STATE_HOVERED || state() == STATE_PRESSED)
293 set_background(MakeBackground(kHoveredButtonBackgroundColor)); 298 set_background(MakeBackground(kHoveredButtonBackgroundColor));
294 else 299 else
295 set_background(NULL); 300 set_background(NULL);
296 } 301 }
297 302
298 } // namespace 303 } // namespace
299 304
300 namespace message_center { 305 namespace message_center {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 if (!IsExpansionNeeded()) { 496 if (!IsExpansionNeeded()) {
492 expand_button()->SetVisible(false); 497 expand_button()->SetVisible(false);
493 } else { 498 } else {
494 gfx::Size expand_size(expand_button()->GetPreferredSize()); 499 gfx::Size expand_size(expand_button()->GetPreferredSize());
495 int expand_y = bottom_y - expand_size.height(); 500 int expand_y = bottom_y - expand_size.height();
496 expand_button()->SetBounds(content_right - expand_size.width(), expand_y, 501 expand_button()->SetBounds(content_right - expand_size.width(), expand_y,
497 expand_size.width(), expand_size.height()); 502 expand_size.width(), expand_size.height());
498 } 503 }
499 } 504 }
500 505
506 void NotificationView::ScrollRectToVisible(const gfx::Rect& rect) {
507 // Notification want to show the whole notification when a part of it (like
508 // a button) gets focused.
509 views::View::ScrollRectToVisible(GetLocalBounds());
510 }
511
501 void NotificationView::ButtonPressed(views::Button* sender, 512 void NotificationView::ButtonPressed(views::Button* sender,
502 const ui::Event& event) { 513 const ui::Event& event) {
503 // See if the button pressed was an action button. 514 // See if the button pressed was an action button.
504 for (size_t i = 0; i < action_buttons_.size(); ++i) { 515 for (size_t i = 0; i < action_buttons_.size(); ++i) {
505 if (sender == action_buttons_[i]) { 516 if (sender == action_buttons_[i]) {
506 observer()->OnButtonClicked(notification_id(), i); 517 observer()->OnButtonClicked(notification_id(), i);
507 return; 518 return;
508 } 519 }
509 } 520 }
510 521
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 556
546 // If there's a title ensure title + message lines <= collapsed line limit. 557 // If there's a title ensure title + message lines <= collapsed line limit.
547 if (title_view_) 558 if (title_view_)
548 return kMessageCollapsedLineLimit - title_view_->GetLinesForWidth(width()); 559 return kMessageCollapsedLineLimit - title_view_->GetLinesForWidth(width());
549 560
550 // If there's no title we get an extra line because message lines are shorter. 561 // If there's no title we get an extra line because message lines are shorter.
551 return kMessageCollapsedLineLimit + 1; 562 return kMessageCollapsedLineLimit + 1;
552 } 563 }
553 564
554 } // namespace message_center 565 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/notification_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698