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

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: Delete debug logs 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
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_;
yoshiki 2016/12/02 12:15:48 Please add DISALLOW_COPY_AND_ASSIGN
yhanada 2016/12/06 02:48:08 Done.
172 };
173
147 ArcCustomNotificationView::ArcCustomNotificationView( 174 ArcCustomNotificationView::ArcCustomNotificationView(
148 ArcCustomNotificationItem* item) 175 ArcCustomNotificationItem* item)
149 : item_(item), 176 : item_(item),
150 notification_key_(item->notification_key()), 177 notification_key_(item->notification_key()),
151 event_forwarder_(new EventForwarder(this)) { 178 event_forwarder_(new EventForwarder(this)) {
152 item_->IncrementWindowRefCount(); 179 item_->IncrementWindowRefCount();
153 item_->AddObserver(this); 180 item_->AddObserver(this);
154 181
155 ArcNotificationSurfaceManager::Get()->AddObserver(this); 182 ArcNotificationSurfaceManager::Get()->AddObserver(this);
156 exo::NotificationSurface* surface = 183 exo::NotificationSurface* surface =
(...skipping 10 matching lines...) Expand all
167 SetSurface(nullptr); 194 SetSurface(nullptr);
168 if (item_) { 195 if (item_) {
169 item_->DecrementWindowRefCount(); 196 item_->DecrementWindowRefCount();
170 item_->RemoveObserver(this); 197 item_->RemoveObserver(this);
171 } 198 }
172 199
173 if (ArcNotificationSurfaceManager::Get()) 200 if (ArcNotificationSurfaceManager::Get())
174 ArcNotificationSurfaceManager::Get()->RemoveObserver(this); 201 ArcNotificationSurfaceManager::Get()->RemoveObserver(this);
175 } 202 }
176 203
204 std::unique_ptr<message_center::CustomNotificationContentViewDelegate>
205 ArcCustomNotificationView::CreateContentViewDelegate() {
206 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this);
207 }
208
177 void ArcCustomNotificationView::CreateFloatingCloseButton() { 209 void ArcCustomNotificationView::CreateFloatingCloseButton() {
178 if (!surface_) 210 if (!surface_)
179 return; 211 return;
180 212
213 // TODO(yhanada): Make the close button get focus after the entire
214 // notification
181 floating_close_button_ = new views::ImageButton(this); 215 floating_close_button_ = new views::ImageButton(this);
182 floating_close_button_->set_background( 216 floating_close_button_->set_background(
183 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT)); 217 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT));
218 floating_close_button_->SetFocusForPlatform();
219 floating_close_button_->SetFocusPainter(
220 views::Painter::CreateSolidFocusPainter(message_center::kFocusBorderColor,
221 gfx::Insets(1, 2, 2, 2)));
184 222
185 // The sizes below are in DIPs. 223 // The sizes below are in DIPs.
186 constexpr int kPaddingFromBorder = 4; 224 constexpr int kPaddingFromBorder = 4;
187 constexpr int kImageSize = 16; 225 constexpr int kImageSize = 16;
188 constexpr int kTouchExtendedPadding = 226 constexpr int kTouchExtendedPadding =
189 message_center::kControlButtonSize - kImageSize - kPaddingFromBorder; 227 message_center::kControlButtonSize - kImageSize - kPaddingFromBorder;
190 floating_close_button_->SetBorder( 228 floating_close_button_->SetBorder(
191 views::CreateEmptyBorder(kPaddingFromBorder, kTouchExtendedPadding, 229 views::CreateEmptyBorder(kPaddingFromBorder, kTouchExtendedPadding,
192 kTouchExtendedPadding, kPaddingFromBorder)); 230 kTouchExtendedPadding, kPaddingFromBorder));
193 231
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 293
256 SetPreferredSize(preferred_size); 294 SetPreferredSize(preferred_size);
257 } 295 }
258 296
259 void ArcCustomNotificationView::UpdateCloseButtonVisiblity() { 297 void ArcCustomNotificationView::UpdateCloseButtonVisiblity() {
260 if (!surface_ || !floating_close_button_widget_) 298 if (!surface_ || !floating_close_button_widget_)
261 return; 299 return;
262 300
263 const bool target_visiblity = 301 const bool target_visiblity =
264 surface_->window()->GetBoundsInScreen().Contains( 302 surface_->window()->GetBoundsInScreen().Contains(
265 display::Screen::GetScreen()->GetCursorScreenPoint()); 303 display::Screen::GetScreen()->GetCursorScreenPoint()) ||
304 floating_close_button_->HasFocus();
266 if (target_visiblity == floating_close_button_widget_->IsVisible()) 305 if (target_visiblity == floating_close_button_widget_->IsVisible())
267 return; 306 return;
268 307
269 if (target_visiblity) 308 if (target_visiblity)
270 floating_close_button_widget_->Show(); 309 floating_close_button_widget_->Show();
271 else 310 else
272 floating_close_button_widget_->Hide(); 311 floating_close_button_widget_->Hide();
273 } 312 }
274 313
275 void ArcCustomNotificationView::UpdatePinnedState() { 314 void ArcCustomNotificationView::UpdatePinnedState() {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 486
448 void ArcCustomNotificationView::OnNotificationSurfaceRemoved( 487 void ArcCustomNotificationView::OnNotificationSurfaceRemoved(
449 exo::NotificationSurface* surface) { 488 exo::NotificationSurface* surface) {
450 if (surface->notification_id() != notification_key_) 489 if (surface->notification_id() != notification_key_)
451 return; 490 return;
452 491
453 SetSurface(nullptr); 492 SetSurface(nullptr);
454 } 493 }
455 494
456 } // namespace arc 495 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698