| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/custom_notification_view.h" | 5 #include "ui/message_center/views/custom_notification_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ui/gfx/geometry/size.h" | 9 #include "ui/gfx/geometry/size.h" |
| 10 #include "ui/message_center/message_center_style.h" | 10 #include "ui/message_center/message_center_style.h" |
| 11 #include "ui/views/background.h" | 11 #include "ui/views/background.h" |
| 12 #include "ui/views/controls/button/image_button.h" | 12 #include "ui/views/controls/button/image_button.h" |
| 13 #include "ui/views/controls/image_view.h" | 13 #include "ui/views/controls/image_view.h" |
| 14 #include "ui/views/painter.h" |
| 14 | 15 |
| 15 namespace message_center { | 16 namespace message_center { |
| 16 | 17 |
| 17 CustomNotificationView::CustomNotificationView( | 18 CustomNotificationView::CustomNotificationView( |
| 18 MessageCenterController* controller, | 19 MessageCenterController* controller, |
| 19 const Notification& notification) | 20 const Notification& notification) |
| 20 : MessageView(controller, notification) { | 21 : MessageView(controller, notification) { |
| 21 DCHECK_EQ(NOTIFICATION_TYPE_CUSTOM, notification.type()); | 22 DCHECK_EQ(NOTIFICATION_TYPE_CUSTOM, notification.type()); |
| 22 | 23 |
| 23 auto custom_content = notification.delegate()->CreateCustomContent(); | 24 auto custom_content = notification.delegate()->CreateCustomContent(); |
| 24 | 25 |
| 25 contents_view_ = custom_content->view.release(); | 26 contents_view_ = custom_content->view.release(); |
| 26 DCHECK(contents_view_); | 27 DCHECK(contents_view_); |
| 27 AddChildView(contents_view_); | 28 AddChildView(contents_view_); |
| 28 | 29 |
| 29 contents_view_delegate_ = std::move(custom_content->delegate); | 30 contents_view_delegate_ = std::move(custom_content->delegate); |
| 30 DCHECK(contents_view_delegate_); | 31 DCHECK(contents_view_delegate_); |
| 31 | 32 |
| 32 if (contents_view_->background()) { | 33 if (contents_view_->background()) { |
| 33 background_view()->background()->SetNativeControlColor( | 34 background_view()->background()->SetNativeControlColor( |
| 34 contents_view_->background()->get_color()); | 35 contents_view_->background()->get_color()); |
| 35 } | 36 } |
| 36 | 37 |
| 37 AddChildView(small_image()); | 38 AddChildView(small_image()); |
| 39 |
| 40 focus_painter_ = views::Painter::CreateSolidFocusPainter( |
| 41 kFocusBorderColor, gfx::Insets(0, 1, 3, 2)); |
| 38 } | 42 } |
| 39 | 43 |
| 40 CustomNotificationView::~CustomNotificationView() {} | 44 CustomNotificationView::~CustomNotificationView() {} |
| 41 | 45 |
| 46 void CustomNotificationView::OnContentFocused() { |
| 47 SchedulePaint(); |
| 48 } |
| 49 |
| 50 void CustomNotificationView::OnContentBlured() { |
| 51 SchedulePaint(); |
| 52 } |
| 53 |
| 42 void CustomNotificationView::SetDrawBackgroundAsActive(bool active) { | 54 void CustomNotificationView::SetDrawBackgroundAsActive(bool active) { |
| 43 // Do nothing if |contents_view_| has a background. | 55 // Do nothing if |contents_view_| has a background. |
| 44 if (contents_view_->background()) | 56 if (contents_view_->background()) |
| 45 return; | 57 return; |
| 46 | 58 |
| 47 MessageView::SetDrawBackgroundAsActive(active); | 59 MessageView::SetDrawBackgroundAsActive(active); |
| 48 } | 60 } |
| 49 | 61 |
| 50 bool CustomNotificationView::IsCloseButtonFocused() const { | 62 bool CustomNotificationView::IsCloseButtonFocused() const { |
| 51 if (!contents_view_delegate_) | 63 if (!contents_view_delegate_) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 74 return gfx::Size(kNotificationWidth, | 86 return gfx::Size(kNotificationWidth, |
| 75 std::max(kMinContentHeight + insets.height(), | 87 std::max(kMinContentHeight + insets.height(), |
| 76 std::min(kMaxContentHeight + insets.height(), | 88 std::min(kMaxContentHeight + insets.height(), |
| 77 contents_height + insets.height()))); | 89 contents_height + insets.height()))); |
| 78 } | 90 } |
| 79 | 91 |
| 80 void CustomNotificationView::Layout() { | 92 void CustomNotificationView::Layout() { |
| 81 MessageView::Layout(); | 93 MessageView::Layout(); |
| 82 | 94 |
| 83 contents_view_->SetBoundsRect(GetContentsBounds()); | 95 contents_view_->SetBoundsRect(GetContentsBounds()); |
| 96 |
| 97 // If the content view claims focus, defer focus handling to the content view. |
| 98 if (contents_view_->IsFocusable()) |
| 99 SetFocusBehavior(FocusBehavior::NEVER); |
| 100 } |
| 101 |
| 102 bool CustomNotificationView::HasFocus() const { |
| 103 // In case that focus handling is defered to the content view, asking the |
| 104 // content view about focus. |
| 105 if (contents_view_ && contents_view_->IsFocusable()) |
| 106 return contents_view_->HasFocus(); |
| 107 else |
| 108 return MessageView::HasFocus(); |
| 109 } |
| 110 |
| 111 void CustomNotificationView::RequestFocus() { |
| 112 if (contents_view_ && contents_view_->IsFocusable()) |
| 113 contents_view_->RequestFocus(); |
| 114 else |
| 115 MessageView::RequestFocus(); |
| 116 } |
| 117 |
| 118 void CustomNotificationView::OnPaint(gfx::Canvas* canvas) { |
| 119 MessageView::OnPaint(canvas); |
| 120 if (contents_view_ && contents_view_->IsFocusable()) |
| 121 views::Painter::PaintFocusPainter(contents_view_, canvas, |
| 122 focus_painter_.get()); |
| 84 } | 123 } |
| 85 | 124 |
| 86 } // namespace message_center | 125 } // namespace message_center |
| OLD | NEW |