Chromium Code Reviews| 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/arc/notification/arc_custom_notification_view.h" | 5 #include "ui/arc/notification/arc_custom_notification_view.h" |
| 6 | 6 |
| 7 #include "components/exo/notification_surface.h" | 7 #include "components/exo/notification_surface.h" |
| 8 #include "components/exo/surface.h" | 8 #include "components/exo/surface.h" |
| 9 #include "third_party/skia/include/core/SkColor.h" | 9 #include "third_party/skia/include/core/SkColor.h" |
| 10 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 ArcCustomNotificationView::~ArcCustomNotificationView() { | 118 ArcCustomNotificationView::~ArcCustomNotificationView() { |
| 119 SetSurface(nullptr); | 119 SetSurface(nullptr); |
| 120 if (item_) | 120 if (item_) |
| 121 item_->RemoveObserver(this); | 121 item_->RemoveObserver(this); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void ArcCustomNotificationView::CreateFloatingCloseButton() { | 124 void ArcCustomNotificationView::CreateFloatingCloseButton() { |
| 125 floating_close_button_ = new views::ImageButton(this); | 125 floating_close_button_ = new views::ImageButton(this); |
| 126 floating_close_button_->set_background( | 126 floating_close_button_->set_background( |
| 127 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT)); | 127 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT)); |
| 128 floating_close_button_->SetBorder( | 128 |
| 129 views::Border::CreateEmptyBorder(5, 5, 5, 5)); | 129 constexpr int kPaddingFromBorder = 4; |
| 130 constexpr int kImageSize = 16; | |
| 131 constexpr int kTouchExtendedPadding = | |
|
yoshiki
2016/08/24 09:24:32
nit: could you mention about units in comment? I a
xiyuan
2016/08/24 15:26:50
Done.
| |
| 132 message_center::kControlButtonSize - kImageSize - kPaddingFromBorder; | |
| 133 floating_close_button_->SetBorder(views::Border::CreateEmptyBorder( | |
| 134 kPaddingFromBorder, kTouchExtendedPadding, kTouchExtendedPadding, | |
| 135 kPaddingFromBorder)); | |
| 130 | 136 |
| 131 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 137 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 132 floating_close_button_->SetImage( | 138 floating_close_button_->SetImage( |
| 133 views::CustomButton::STATE_NORMAL, | 139 views::CustomButton::STATE_NORMAL, |
| 134 rb.GetImageSkiaNamed(IDR_NOTIFICATION_CLOSE)); | 140 rb.GetImageSkiaNamed(IDR_ARC_NOTIFICATION_CLOSE)); |
| 135 floating_close_button_->SetImage( | |
| 136 views::CustomButton::STATE_HOVERED, | |
| 137 rb.GetImageSkiaNamed(IDR_NOTIFICATION_CLOSE_HOVER)); | |
| 138 floating_close_button_->SetImage( | |
| 139 views::CustomButton::STATE_PRESSED, | |
| 140 rb.GetImageSkiaNamed(IDR_NOTIFICATION_CLOSE_PRESSED)); | |
| 141 floating_close_button_->set_animate_on_state_change(false); | 141 floating_close_button_->set_animate_on_state_change(false); |
| 142 floating_close_button_->SetAccessibleName(l10n_util::GetStringUTF16( | 142 floating_close_button_->SetAccessibleName(l10n_util::GetStringUTF16( |
| 143 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); | 143 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); |
| 144 | 144 |
| 145 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 145 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
| 146 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 146 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 147 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 147 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 148 params.parent = surface_->window(); | 148 params.parent = surface_->window(); |
| 149 | 149 |
| 150 floating_close_button_widget_.reset(new views::Widget); | 150 floating_close_button_widget_.reset(new views::Widget); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 gfx::Rect close_button_bounds(floating_close_button_->GetPreferredSize()); | 250 gfx::Rect close_button_bounds(floating_close_button_->GetPreferredSize()); |
| 251 close_button_bounds.set_x(surface_local_bounds.right() - | 251 close_button_bounds.set_x(surface_local_bounds.right() - |
| 252 close_button_bounds.width()); | 252 close_button_bounds.width()); |
| 253 close_button_bounds.set_y(surface_local_bounds.y()); | 253 close_button_bounds.set_y(surface_local_bounds.y()); |
| 254 floating_close_button_widget_->SetBounds(close_button_bounds); | 254 floating_close_button_widget_->SetBounds(close_button_bounds); |
| 255 | 255 |
| 256 UpdateCloseButtonVisiblity(); | 256 UpdateCloseButtonVisiblity(); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void ArcCustomNotificationView::OnKeyEvent(ui::KeyEvent* event) { | 259 void ArcCustomNotificationView::OnKeyEvent(ui::KeyEvent* event) { |
| 260 // Do not handle event targeted to the floating close button. | |
| 261 if (floating_close_button_widget_ && event->target() && | |
| 262 floating_close_button_widget_->GetNativeWindow() == event->target()) { | |
| 263 return; | |
| 264 } | |
| 265 | |
| 260 // Forward to parent CustomNotificationView to handle keyboard dismissal. | 266 // Forward to parent CustomNotificationView to handle keyboard dismissal. |
| 261 parent()->OnKeyEvent(event); | 267 parent()->OnKeyEvent(event); |
| 262 } | 268 } |
| 263 | 269 |
| 264 void ArcCustomNotificationView::OnGestureEvent(ui::GestureEvent* event) { | 270 void ArcCustomNotificationView::OnGestureEvent(ui::GestureEvent* event) { |
| 271 // Do not handle event targeted to the floating close button. | |
| 272 if (floating_close_button_widget_ && event->target() && | |
| 273 floating_close_button_widget_->GetNativeWindow() == event->target()) { | |
| 274 return; | |
| 275 } | |
| 276 | |
| 265 // Forward to parent CustomNotificationView to handle sliding out. | 277 // Forward to parent CustomNotificationView to handle sliding out. |
| 266 parent()->OnGestureEvent(event); | 278 parent()->OnGestureEvent(event); |
| 267 slide_helper_->Update(); | 279 slide_helper_->Update(); |
| 268 } | 280 } |
| 269 | 281 |
| 270 void ArcCustomNotificationView::OnMouseEntered(const ui::MouseEvent&) { | 282 void ArcCustomNotificationView::OnMouseEntered(const ui::MouseEvent&) { |
| 271 UpdateCloseButtonVisiblity(); | 283 UpdateCloseButtonVisiblity(); |
| 272 } | 284 } |
| 273 | 285 |
| 274 void ArcCustomNotificationView::OnMouseExited(const ui::MouseEvent&) { | 286 void ArcCustomNotificationView::OnMouseExited(const ui::MouseEvent&) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 } else if (!item_->pinned() && !floating_close_button_widget_) { | 320 } else if (!item_->pinned() && !floating_close_button_widget_) { |
| 309 CreateFloatingCloseButton(); | 321 CreateFloatingCloseButton(); |
| 310 } | 322 } |
| 311 } | 323 } |
| 312 | 324 |
| 313 void ArcCustomNotificationView::OnItemNotificationSurfaceRemoved() { | 325 void ArcCustomNotificationView::OnItemNotificationSurfaceRemoved() { |
| 314 SetSurface(nullptr); | 326 SetSurface(nullptr); |
| 315 } | 327 } |
| 316 | 328 |
| 317 } // namespace arc | 329 } // namespace arc |
| OLD | NEW |