| OLD | NEW |
| 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/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 NotificationButton(views::ButtonListener* listener); | 315 NotificationButton(views::ButtonListener* listener); |
| 316 virtual ~NotificationButton(); | 316 virtual ~NotificationButton(); |
| 317 | 317 |
| 318 void SetIcon(const gfx::ImageSkia& icon); | 318 void SetIcon(const gfx::ImageSkia& icon); |
| 319 void SetTitle(const string16& title); | 319 void SetTitle(const string16& title); |
| 320 | 320 |
| 321 // Overridden from views::View: | 321 // Overridden from views::View: |
| 322 virtual gfx::Size GetPreferredSize() OVERRIDE; | 322 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 323 virtual int GetHeightForWidth(int width) OVERRIDE; | 323 virtual int GetHeightForWidth(int width) OVERRIDE; |
| 324 virtual void OnFocus() OVERRIDE; | 324 virtual void OnFocus() OVERRIDE; |
| 325 virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; | |
| 326 | 325 |
| 327 // Overridden from views::CustomButton: | 326 // Overridden from views::CustomButton: |
| 328 virtual void StateChanged() OVERRIDE; | 327 virtual void StateChanged() OVERRIDE; |
| 329 | 328 |
| 330 private: | 329 private: |
| 331 views::ImageView* icon_; | 330 views::ImageView* icon_; |
| 332 views::Label* title_; | 331 views::Label* title_; |
| 333 }; | 332 }; |
| 334 | 333 |
| 335 NotificationButton::NotificationButton(views::ButtonListener* listener) | 334 NotificationButton::NotificationButton(views::ButtonListener* listener) |
| 336 : views::CustomButton(listener), | 335 : views::CustomButton(listener), |
| 337 icon_(NULL), | 336 icon_(NULL), |
| 338 title_(NULL) { | 337 title_(NULL) { |
| 339 set_focusable(true); | 338 set_focusable(true); |
| 340 set_request_focus_on_press(false); | 339 set_request_focus_on_press(false); |
| 341 set_notify_enter_exit_on_child(true); | 340 set_notify_enter_exit_on_child(true); |
| 342 SetLayoutManager( | 341 SetLayoutManager( |
| 343 new views::BoxLayout(views::BoxLayout::kHorizontal, | 342 new views::BoxLayout(views::BoxLayout::kHorizontal, |
| 344 message_center::kButtonHorizontalPadding, | 343 message_center::kButtonHorizontalPadding, |
| 345 kButtonVecticalPadding, | 344 kButtonVecticalPadding, |
| 346 message_center::kButtonIconToTitlePadding)); | 345 message_center::kButtonIconToTitlePadding)); |
| 346 set_focus_border(views::FocusBorder::CreateSolidFocusBorder( |
| 347 message_center::kFocusBorderColor, |
| 348 gfx::Insets(1, 2, 2, 2))); |
| 347 } | 349 } |
| 348 | 350 |
| 349 NotificationButton::~NotificationButton() { | 351 NotificationButton::~NotificationButton() { |
| 350 } | 352 } |
| 351 | 353 |
| 352 void NotificationButton::SetIcon(const gfx::ImageSkia& image) { | 354 void NotificationButton::SetIcon(const gfx::ImageSkia& image) { |
| 353 if (icon_ != NULL) | 355 if (icon_ != NULL) |
| 354 delete icon_; // This removes the icon from this view's children. | 356 delete icon_; // This removes the icon from this view's children. |
| 355 if (image.isNull()) { | 357 if (image.isNull()) { |
| 356 icon_ = NULL; | 358 icon_ = NULL; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 | 392 |
| 391 int NotificationButton::GetHeightForWidth(int width) { | 393 int NotificationButton::GetHeightForWidth(int width) { |
| 392 return message_center::kButtonHeight; | 394 return message_center::kButtonHeight; |
| 393 } | 395 } |
| 394 | 396 |
| 395 void NotificationButton::OnFocus() { | 397 void NotificationButton::OnFocus() { |
| 396 views::CustomButton::OnFocus(); | 398 views::CustomButton::OnFocus(); |
| 397 ScrollRectToVisible(GetLocalBounds()); | 399 ScrollRectToVisible(GetLocalBounds()); |
| 398 } | 400 } |
| 399 | 401 |
| 400 void NotificationButton::OnPaintFocusBorder(gfx::Canvas* canvas) { | |
| 401 if (HasFocus()) { | |
| 402 canvas->DrawRect(gfx::Rect(2, 1, width() - 4, height() - 3), | |
| 403 message_center::kFocusBorderColor); | |
| 404 } | |
| 405 } | |
| 406 | |
| 407 void NotificationButton::StateChanged() { | 402 void NotificationButton::StateChanged() { |
| 408 if (state() == STATE_HOVERED || state() == STATE_PRESSED) { | 403 if (state() == STATE_HOVERED || state() == STATE_PRESSED) { |
| 409 set_background( | 404 set_background( |
| 410 MakeBackground(message_center::kHoveredButtonBackgroundColor)); | 405 MakeBackground(message_center::kHoveredButtonBackgroundColor)); |
| 411 } else { | 406 } else { |
| 412 set_background(NULL); | 407 set_background(NULL); |
| 413 } | 408 } |
| 414 } | 409 } |
| 415 | 410 |
| 416 } // namespace | 411 } // namespace |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 return message_view_ ? | 832 return message_view_ ? |
| 838 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; | 833 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; |
| 839 } | 834 } |
| 840 | 835 |
| 841 int NotificationView::GetMessageHeight(int width, int limit) { | 836 int NotificationView::GetMessageHeight(int width, int limit) { |
| 842 return message_view_ ? | 837 return message_view_ ? |
| 843 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 838 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
| 844 } | 839 } |
| 845 | 840 |
| 846 } // namespace message_center | 841 } // namespace message_center |
| OLD | NEW |