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

Side by Side Diff: ui/arc/notification/arc_custom_notification_view.cc

Issue 2547433002: Transfer responsibility for providing a close button for a notification to each implementation of M… (Closed)
Patch Set: WrapUnique -> MakeUnique Created 4 years 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
« no previous file with comments | « ui/arc/notification/arc_custom_notification_view.h ('k') | ui/message_center/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "components/exo/notification_surface.h" 8 #include "components/exo/notification_surface.h"
9 #include "components/exo/surface.h" 9 #include "components/exo/surface.h"
10 #include "third_party/skia/include/core/SkColor.h" 10 #include "third_party/skia/include/core/SkColor.h"
11 #include "ui/base/l10n/l10n_util.h" 11 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/base/resource/resource_bundle.h" 12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/compositor/layer_animation_observer.h" 13 #include "ui/compositor/layer_animation_observer.h"
14 #include "ui/display/screen.h" 14 #include "ui/display/screen.h"
15 #include "ui/events/event_handler.h" 15 #include "ui/events/event_handler.h"
16 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/image/image_skia.h" 17 #include "ui/gfx/image/image_skia.h"
18 #include "ui/gfx/transform.h" 18 #include "ui/gfx/transform.h"
19 #include "ui/message_center/message_center_style.h" 19 #include "ui/message_center/message_center_style.h"
20 #include "ui/resources/grit/ui_resources.h" 20 #include "ui/resources/grit/ui_resources.h"
21 #include "ui/strings/grit/ui_strings.h" 21 #include "ui/strings/grit/ui_strings.h"
22 #include "ui/views/background.h" 22 #include "ui/views/background.h"
23 #include "ui/views/border.h" 23 #include "ui/views/border.h"
24 #include "ui/views/controls/button/image_button.h" 24 #include "ui/views/controls/button/image_button.h"
25 #include "ui/views/painter.h"
25 #include "ui/views/widget/widget.h" 26 #include "ui/views/widget/widget.h"
26 #include "ui/wm/core/window_util.h" 27 #include "ui/wm/core/window_util.h"
27 28
28 namespace arc { 29 namespace arc {
29 30
30 class ArcCustomNotificationView::EventForwarder : public ui::EventHandler { 31 class ArcCustomNotificationView::EventForwarder : public ui::EventHandler {
31 public: 32 public:
32 explicit EventForwarder(ArcCustomNotificationView* owner) : owner_(owner) {} 33 explicit EventForwarder(ArcCustomNotificationView* owner) : owner_(owner) {}
33 ~EventForwarder() override = default; 34 ~EventForwarder() override = default;
34 35
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 138 }
138 void OnLayerAnimationScheduled(ui::LayerAnimationSequence* seq) override {} 139 void OnLayerAnimationScheduled(ui::LayerAnimationSequence* seq) override {}
139 140
140 ArcCustomNotificationView* const owner_; 141 ArcCustomNotificationView* const owner_;
141 bool sliding_ = false; 142 bool sliding_ = false;
142 std::unique_ptr<ui::LayerTreeOwner> surface_copy_; 143 std::unique_ptr<ui::LayerTreeOwner> surface_copy_;
143 144
144 DISALLOW_COPY_AND_ASSIGN(SlideHelper); 145 DISALLOW_COPY_AND_ASSIGN(SlideHelper);
145 }; 146 };
146 147
148 class ArcCustomNotificationView::ContentViewDelegate
149 : public message_center::CustomNotificationContentViewDelegate {
150 public:
151 explicit ContentViewDelegate(ArcCustomNotificationView* owner)
152 : owner_(owner) {}
153
154 bool IsCloseButtonFocused() const override {
155 if (owner_->floating_close_button_ == nullptr)
156 return false;
157 return owner_->floating_close_button_->HasFocus();
158 }
159
160 void RequestFocusOnCloseButton() override {
161 if (owner_->floating_close_button_)
162 owner_->floating_close_button_->RequestFocus();
163 owner_->UpdateCloseButtonVisiblity();
164 }
165
166 bool IsPinned() const override {
167 return owner_->floating_close_button_ == nullptr;
168 }
169
170 private:
171 ArcCustomNotificationView* const owner_;
172
173 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate);
174 };
175
147 ArcCustomNotificationView::ArcCustomNotificationView( 176 ArcCustomNotificationView::ArcCustomNotificationView(
148 ArcCustomNotificationItem* item) 177 ArcCustomNotificationItem* item)
149 : item_(item), 178 : item_(item),
150 notification_key_(item->notification_key()), 179 notification_key_(item->notification_key()),
151 event_forwarder_(new EventForwarder(this)) { 180 event_forwarder_(new EventForwarder(this)) {
152 item_->IncrementWindowRefCount(); 181 item_->IncrementWindowRefCount();
153 item_->AddObserver(this); 182 item_->AddObserver(this);
154 183
155 ArcNotificationSurfaceManager::Get()->AddObserver(this); 184 ArcNotificationSurfaceManager::Get()->AddObserver(this);
156 exo::NotificationSurface* surface = 185 exo::NotificationSurface* surface =
(...skipping 10 matching lines...) Expand all
167 SetSurface(nullptr); 196 SetSurface(nullptr);
168 if (item_) { 197 if (item_) {
169 item_->DecrementWindowRefCount(); 198 item_->DecrementWindowRefCount();
170 item_->RemoveObserver(this); 199 item_->RemoveObserver(this);
171 } 200 }
172 201
173 if (ArcNotificationSurfaceManager::Get()) 202 if (ArcNotificationSurfaceManager::Get())
174 ArcNotificationSurfaceManager::Get()->RemoveObserver(this); 203 ArcNotificationSurfaceManager::Get()->RemoveObserver(this);
175 } 204 }
176 205
206 std::unique_ptr<message_center::CustomNotificationContentViewDelegate>
207 ArcCustomNotificationView::CreateContentViewDelegate() {
208 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this);
209 }
210
177 void ArcCustomNotificationView::CreateFloatingCloseButton() { 211 void ArcCustomNotificationView::CreateFloatingCloseButton() {
178 if (!surface_) 212 if (!surface_)
179 return; 213 return;
180 214
215 // TODO(yhanada): Make the close button get focus after the entire
216 // notification
181 floating_close_button_ = new views::ImageButton(this); 217 floating_close_button_ = new views::ImageButton(this);
182 floating_close_button_->set_background( 218 floating_close_button_->set_background(
183 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT)); 219 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT));
220 floating_close_button_->SetFocusForPlatform();
221 floating_close_button_->SetFocusPainter(
222 views::Painter::CreateSolidFocusPainter(message_center::kFocusBorderColor,
223 gfx::Insets(1, 2, 2, 2)));
184 224
185 // The sizes below are in DIPs. 225 // The sizes below are in DIPs.
186 constexpr int kPaddingFromBorder = 4; 226 constexpr int kPaddingFromBorder = 4;
187 constexpr int kImageSize = 16; 227 constexpr int kImageSize = 16;
188 constexpr int kTouchExtendedPadding = 228 constexpr int kTouchExtendedPadding =
189 message_center::kControlButtonSize - kImageSize - kPaddingFromBorder; 229 message_center::kControlButtonSize - kImageSize - kPaddingFromBorder;
190 floating_close_button_->SetBorder( 230 floating_close_button_->SetBorder(
191 views::CreateEmptyBorder(kPaddingFromBorder, kTouchExtendedPadding, 231 views::CreateEmptyBorder(kPaddingFromBorder, kTouchExtendedPadding,
192 kTouchExtendedPadding, kPaddingFromBorder)); 232 kTouchExtendedPadding, kPaddingFromBorder));
193 233
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 295
256 SetPreferredSize(preferred_size); 296 SetPreferredSize(preferred_size);
257 } 297 }
258 298
259 void ArcCustomNotificationView::UpdateCloseButtonVisiblity() { 299 void ArcCustomNotificationView::UpdateCloseButtonVisiblity() {
260 if (!surface_ || !floating_close_button_widget_) 300 if (!surface_ || !floating_close_button_widget_)
261 return; 301 return;
262 302
263 const bool target_visiblity = 303 const bool target_visiblity =
264 surface_->window()->GetBoundsInScreen().Contains( 304 surface_->window()->GetBoundsInScreen().Contains(
265 display::Screen::GetScreen()->GetCursorScreenPoint()); 305 display::Screen::GetScreen()->GetCursorScreenPoint()) ||
306 floating_close_button_->HasFocus();
266 if (target_visiblity == floating_close_button_widget_->IsVisible()) 307 if (target_visiblity == floating_close_button_widget_->IsVisible())
267 return; 308 return;
268 309
269 if (target_visiblity) 310 if (target_visiblity)
270 floating_close_button_widget_->Show(); 311 floating_close_button_widget_->Show();
271 else 312 else
272 floating_close_button_widget_->Hide(); 313 floating_close_button_widget_->Hide();
273 } 314 }
274 315
275 void ArcCustomNotificationView::UpdatePinnedState() { 316 void ArcCustomNotificationView::UpdatePinnedState() {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 488
448 void ArcCustomNotificationView::OnNotificationSurfaceRemoved( 489 void ArcCustomNotificationView::OnNotificationSurfaceRemoved(
449 exo::NotificationSurface* surface) { 490 exo::NotificationSurface* surface) {
450 if (surface->notification_id() != notification_key_) 491 if (surface->notification_id() != notification_key_)
451 return; 492 return;
452 493
453 SetSurface(nullptr); 494 SetSurface(nullptr);
454 } 495 }
455 496
456 } // namespace arc 497 } // namespace arc
OLDNEW
« no previous file with comments | « ui/arc/notification/arc_custom_notification_view.h ('k') | ui/message_center/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698