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

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

Issue 2906323002: Rename ArcCustomNotificationView to ArcNotificationContentView (Closed)
Patch Set: Created 3 years, 6 months 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_notification_content_view.h"
6 6
7 #include "ash/wm/window_util.h" 7 #include "ash/wm/window_util.h"
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "components/exo/notification_surface.h" 10 #include "components/exo/notification_surface.h"
11 #include "components/exo/surface.h" 11 #include "components/exo/surface.h"
12 #include "ui/accessibility/ax_action_data.h" 12 #include "ui/accessibility/ax_action_data.h"
13 #include "ui/arc/notification/arc_notification_view.h" 13 #include "ui/arc/notification/arc_notification_view.h"
14 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
(...skipping 25 matching lines...) Expand all
41 SkColor GetControlButtonBackgroundColor( 41 SkColor GetControlButtonBackgroundColor(
42 const mojom::ArcNotificationShownContents& shown_contents) { 42 const mojom::ArcNotificationShownContents& shown_contents) {
43 if (shown_contents == mojom::ArcNotificationShownContents::CONTENTS_SHOWN) 43 if (shown_contents == mojom::ArcNotificationShownContents::CONTENTS_SHOWN)
44 return message_center::kControlButtonBackgroundColor; 44 return message_center::kControlButtonBackgroundColor;
45 else 45 else
46 return SK_ColorTRANSPARENT; 46 return SK_ColorTRANSPARENT;
47 } 47 }
48 48
49 } // namespace 49 } // namespace
50 50
51 class ArcCustomNotificationView::EventForwarder : public ui::EventHandler { 51 class ArcNotificationContentView::EventForwarder : public ui::EventHandler {
52 public: 52 public:
53 explicit EventForwarder(ArcCustomNotificationView* owner) : owner_(owner) {} 53 explicit EventForwarder(ArcNotificationContentView* owner) : owner_(owner) {}
54 ~EventForwarder() override = default; 54 ~EventForwarder() override = default;
55 55
56 private: 56 private:
57 // ui::EventHandler 57 // ui::EventHandler
58 void OnEvent(ui::Event* event) override { 58 void OnEvent(ui::Event* event) override {
59 // Do not forward event targeted to the floating close button so that 59 // Do not forward event targeted to the floating close button so that
60 // keyboard press and tap are handled properly. 60 // keyboard press and tap are handled properly.
61 if (owner_->floating_control_buttons_widget_ && event->target() && 61 if (owner_->floating_control_buttons_widget_ && event->target() &&
62 owner_->floating_control_buttons_widget_->GetNativeWindow() == 62 owner_->floating_control_buttons_widget_->GetNativeWindow() ==
63 event->target()) { 63 event->target()) {
(...skipping 25 matching lines...) Expand all
89 widget->OnMouseEvent(located_event->AsMouseEvent()); 89 widget->OnMouseEvent(located_event->AsMouseEvent());
90 } else if (located_event->IsScrollEvent()) { 90 } else if (located_event->IsScrollEvent()) {
91 widget->OnScrollEvent(located_event->AsScrollEvent()); 91 widget->OnScrollEvent(located_event->AsScrollEvent());
92 } else if (located_event->IsGestureEvent() && 92 } else if (located_event->IsGestureEvent() &&
93 event->type() != ui::ET_GESTURE_TAP) { 93 event->type() != ui::ET_GESTURE_TAP) {
94 widget->OnGestureEvent(located_event->AsGestureEvent()); 94 widget->OnGestureEvent(located_event->AsGestureEvent());
95 } 95 }
96 } 96 }
97 } 97 }
98 98
99 ArcCustomNotificationView* const owner_; 99 ArcNotificationContentView* const owner_;
100 100
101 DISALLOW_COPY_AND_ASSIGN(EventForwarder); 101 DISALLOW_COPY_AND_ASSIGN(EventForwarder);
102 }; 102 };
103 103
104 class ArcCustomNotificationView::SlideHelper 104 class ArcNotificationContentView::SlideHelper
105 : public ui::LayerAnimationObserver { 105 : public ui::LayerAnimationObserver {
106 public: 106 public:
107 explicit SlideHelper(ArcCustomNotificationView* owner) : owner_(owner) { 107 explicit SlideHelper(ArcNotificationContentView* owner) : owner_(owner) {
108 GetSlideOutLayer()->GetAnimator()->AddObserver(this); 108 GetSlideOutLayer()->GetAnimator()->AddObserver(this);
109 109
110 // Reset opacity to 1 to handle to case when the surface is sliding before 110 // Reset opacity to 1 to handle to case when the surface is sliding before
111 // getting managed by this class, e.g. sliding in a popup before showing 111 // getting managed by this class, e.g. sliding in a popup before showing
112 // in a message center view. 112 // in a message center view.
113 if (owner_->surface_ && owner_->surface_->window()) 113 if (owner_->surface_ && owner_->surface_->window())
114 owner_->surface_->window()->layer()->SetOpacity(1.0f); 114 owner_->surface_->window()->layer()->SetOpacity(1.0f);
115 } 115 }
116 ~SlideHelper() override { 116 ~SlideHelper() override {
117 if (GetSlideOutLayer()) 117 if (GetSlideOutLayer())
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 161
162 // ui::LayerAnimationObserver 162 // ui::LayerAnimationObserver
163 void OnLayerAnimationEnded(ui::LayerAnimationSequence* seq) override { 163 void OnLayerAnimationEnded(ui::LayerAnimationSequence* seq) override {
164 Update(); 164 Update();
165 } 165 }
166 void OnLayerAnimationAborted(ui::LayerAnimationSequence* seq) override { 166 void OnLayerAnimationAborted(ui::LayerAnimationSequence* seq) override {
167 Update(); 167 Update();
168 } 168 }
169 void OnLayerAnimationScheduled(ui::LayerAnimationSequence* seq) override {} 169 void OnLayerAnimationScheduled(ui::LayerAnimationSequence* seq) override {}
170 170
171 ArcCustomNotificationView* const owner_; 171 ArcNotificationContentView* const owner_;
172 bool sliding_ = false; 172 bool sliding_ = false;
173 std::unique_ptr<ui::LayerTreeOwner> surface_copy_; 173 std::unique_ptr<ui::LayerTreeOwner> surface_copy_;
174 174
175 DISALLOW_COPY_AND_ASSIGN(SlideHelper); 175 DISALLOW_COPY_AND_ASSIGN(SlideHelper);
176 }; 176 };
177 177
178 class ArcCustomNotificationView::ContentViewDelegate 178 class ArcNotificationContentView::ContentViewDelegate
179 : public ArcNotificationContentViewDelegate { 179 : public ArcNotificationContentViewDelegate {
180 public: 180 public:
181 explicit ContentViewDelegate(ArcCustomNotificationView* owner) 181 explicit ContentViewDelegate(ArcNotificationContentView* owner)
182 : owner_(owner) {} 182 : owner_(owner) {}
183 183
184 bool IsCloseButtonFocused() const override { 184 bool IsCloseButtonFocused() const override {
185 if (!owner_->close_button_) 185 if (!owner_->close_button_)
186 return false; 186 return false;
187 return owner_->close_button_->HasFocus(); 187 return owner_->close_button_->HasFocus();
188 } 188 }
189 189
190 void RequestFocusOnCloseButton() override { 190 void RequestFocusOnCloseButton() override {
191 if (owner_->close_button_) 191 if (owner_->close_button_)
192 owner_->close_button_->RequestFocus(); 192 owner_->close_button_->RequestFocus();
193 owner_->UpdateControlButtonsVisibility(); 193 owner_->UpdateControlButtonsVisibility();
194 } 194 }
195 195
196 void UpdateControlButtonsVisibility() override { 196 void UpdateControlButtonsVisibility() override {
197 owner_->UpdateControlButtonsVisibility(); 197 owner_->UpdateControlButtonsVisibility();
198 } 198 }
199 199
200 void OnSlideChanged() override { 200 void OnSlideChanged() override {
201 if (owner_->slide_helper_) 201 if (owner_->slide_helper_)
202 owner_->slide_helper_->Update(); 202 owner_->slide_helper_->Update();
203 } 203 }
204 204
205 private: 205 private:
206 ArcCustomNotificationView* const owner_; 206 ArcNotificationContentView* const owner_;
207 207
208 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); 208 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate);
209 }; 209 };
210 210
211 ArcCustomNotificationView::ControlButton::ControlButton( 211 ArcNotificationContentView::ControlButton::ControlButton(
212 ArcCustomNotificationView* owner) 212 ArcNotificationContentView* owner)
213 : message_center::PaddedButton(owner), owner_(owner) { 213 : message_center::PaddedButton(owner), owner_(owner) {
214 if (owner_->item_) { 214 if (owner_->item_) {
215 set_background(views::Background::CreateSolidBackground( 215 set_background(views::Background::CreateSolidBackground(
216 GetControlButtonBackgroundColor(owner_->item_->GetShownContents()))); 216 GetControlButtonBackgroundColor(owner_->item_->GetShownContents())));
217 } else { 217 } else {
218 set_background(views::Background::CreateSolidBackground( 218 set_background(views::Background::CreateSolidBackground(
219 message_center::kControlButtonBackgroundColor)); 219 message_center::kControlButtonBackgroundColor));
220 } 220 }
221 } 221 }
222 222
223 void ArcCustomNotificationView::ControlButton::OnFocus() { 223 void ArcNotificationContentView::ControlButton::OnFocus() {
224 message_center::PaddedButton::OnFocus(); 224 message_center::PaddedButton::OnFocus();
225 owner_->UpdateControlButtonsVisibility(); 225 owner_->UpdateControlButtonsVisibility();
226 } 226 }
227 227
228 void ArcCustomNotificationView::ControlButton::OnBlur() { 228 void ArcNotificationContentView::ControlButton::OnBlur() {
229 message_center::PaddedButton::OnBlur(); 229 message_center::PaddedButton::OnBlur();
230 owner_->UpdateControlButtonsVisibility(); 230 owner_->UpdateControlButtonsVisibility();
231 } 231 }
232 232
233 ArcCustomNotificationView::ArcCustomNotificationView(ArcNotificationItem* item) 233 ArcNotificationContentView::ArcNotificationContentView(
234 ArcNotificationItem* item)
234 : item_(item), 235 : item_(item),
235 notification_key_(item->GetNotificationKey()), 236 notification_key_(item->GetNotificationKey()),
236 event_forwarder_(new EventForwarder(this)) { 237 event_forwarder_(new EventForwarder(this)) {
237 SetFocusBehavior(FocusBehavior::ALWAYS); 238 SetFocusBehavior(FocusBehavior::ALWAYS);
238 239
239 item_->IncrementWindowRefCount(); 240 item_->IncrementWindowRefCount();
240 item_->AddObserver(this); 241 item_->AddObserver(this);
241 242
242 auto* surface_manager = ArcNotificationSurfaceManager::Get(); 243 auto* surface_manager = ArcNotificationSurfaceManager::Get();
243 if (surface_manager) { 244 if (surface_manager) {
244 surface_manager->AddObserver(this); 245 surface_manager->AddObserver(this);
245 exo::NotificationSurface* surface = 246 exo::NotificationSurface* surface =
246 surface_manager->GetSurface(notification_key_); 247 surface_manager->GetSurface(notification_key_);
247 if (surface) 248 if (surface)
248 OnNotificationSurfaceAdded(surface); 249 OnNotificationSurfaceAdded(surface);
249 } 250 }
250 251
251 // Create a layer as an anchor to insert surface copy during a slide. 252 // Create a layer as an anchor to insert surface copy during a slide.
252 SetPaintToLayer(); 253 SetPaintToLayer();
253 UpdatePreferredSize(); 254 UpdatePreferredSize();
254 } 255 }
255 256
256 ArcCustomNotificationView::~ArcCustomNotificationView() { 257 ArcNotificationContentView::~ArcNotificationContentView() {
257 SetSurface(nullptr); 258 SetSurface(nullptr);
258 259
259 auto* surface_manager = ArcNotificationSurfaceManager::Get(); 260 auto* surface_manager = ArcNotificationSurfaceManager::Get();
260 if (surface_manager) 261 if (surface_manager)
261 surface_manager->RemoveObserver(this); 262 surface_manager->RemoveObserver(this);
262 if (item_) { 263 if (item_) {
263 item_->RemoveObserver(this); 264 item_->RemoveObserver(this);
264 item_->DecrementWindowRefCount(); 265 item_->DecrementWindowRefCount();
265 } 266 }
266 } 267 }
267 268
268 std::unique_ptr<ArcNotificationContentViewDelegate> 269 std::unique_ptr<ArcNotificationContentViewDelegate>
269 ArcCustomNotificationView::CreateContentViewDelegate() { 270 ArcNotificationContentView::CreateContentViewDelegate() {
270 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this); 271 return base::MakeUnique<ArcNotificationContentView::ContentViewDelegate>(
272 this);
271 } 273 }
272 274
273 void ArcCustomNotificationView::CreateCloseButton() { 275 void ArcNotificationContentView::CreateCloseButton() {
274 DCHECK(control_buttons_view_); 276 DCHECK(control_buttons_view_);
275 DCHECK(item_); 277 DCHECK(item_);
276 278
277 close_button_ = base::MakeUnique<ControlButton>(this); 279 close_button_ = base::MakeUnique<ControlButton>(this);
278 close_button_->SetImage(views::CustomButton::STATE_NORMAL, 280 close_button_->SetImage(views::CustomButton::STATE_NORMAL,
279 message_center::GetCloseIcon()); 281 message_center::GetCloseIcon());
280 close_button_->SetAccessibleName(l10n_util::GetStringUTF16( 282 close_button_->SetAccessibleName(l10n_util::GetStringUTF16(
281 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); 283 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME));
282 close_button_->SetTooltipText(l10n_util::GetStringUTF16( 284 close_button_->SetTooltipText(l10n_util::GetStringUTF16(
283 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP)); 285 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP));
284 close_button_->set_owned_by_client(); 286 close_button_->set_owned_by_client();
285 control_buttons_view_->AddChildView(close_button_.get()); 287 control_buttons_view_->AddChildView(close_button_.get());
286 } 288 }
287 289
288 void ArcCustomNotificationView::CreateSettingsButton() { 290 void ArcNotificationContentView::CreateSettingsButton() {
289 DCHECK(control_buttons_view_); 291 DCHECK(control_buttons_view_);
290 DCHECK(item_); 292 DCHECK(item_);
291 293
292 settings_button_ = new ControlButton(this); 294 settings_button_ = new ControlButton(this);
293 settings_button_->SetImage(views::CustomButton::STATE_NORMAL, 295 settings_button_->SetImage(views::CustomButton::STATE_NORMAL,
294 message_center::GetSettingsIcon()); 296 message_center::GetSettingsIcon());
295 settings_button_->SetAccessibleName(l10n_util::GetStringUTF16( 297 settings_button_->SetAccessibleName(l10n_util::GetStringUTF16(
296 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); 298 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME));
297 settings_button_->SetTooltipText(l10n_util::GetStringUTF16( 299 settings_button_->SetTooltipText(l10n_util::GetStringUTF16(
298 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); 300 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME));
299 control_buttons_view_->AddChildView(settings_button_); 301 control_buttons_view_->AddChildView(settings_button_);
300 } 302 }
301 303
302 void ArcCustomNotificationView::MaybeCreateFloatingControlButtons() { 304 void ArcNotificationContentView::MaybeCreateFloatingControlButtons() {
303 // Floating close button is a transient child of |surface_| and also part 305 // Floating close button is a transient child of |surface_| and also part
304 // of the hosting widget's focus chain. It could only be created when both 306 // of the hosting widget's focus chain. It could only be created when both
305 // are present. Further, if we are being destroyed (|item_| is null), don't 307 // are present. Further, if we are being destroyed (|item_| is null), don't
306 // create the control buttons. 308 // create the control buttons.
307 if (!surface_ || !GetWidget() || !item_) 309 if (!surface_ || !GetWidget() || !item_)
308 return; 310 return;
309 311
310 // Creates the control_buttons_view_, which collects all control buttons into 312 // Creates the control_buttons_view_, which collects all control buttons into
311 // a horizontal box. 313 // a horizontal box.
312 control_buttons_view_ = new views::View(); 314 control_buttons_view_ = new views::View();
(...skipping 15 matching lines...) Expand all
328 floating_control_buttons_widget_->SetContentsView(control_buttons_view_); 330 floating_control_buttons_widget_->SetContentsView(control_buttons_view_);
329 331
330 // Put the close button into the focus chain. 332 // Put the close button into the focus chain.
331 floating_control_buttons_widget_->SetFocusTraversableParent( 333 floating_control_buttons_widget_->SetFocusTraversableParent(
332 GetWidget()->GetFocusTraversable()); 334 GetWidget()->GetFocusTraversable());
333 floating_control_buttons_widget_->SetFocusTraversableParentView(this); 335 floating_control_buttons_widget_->SetFocusTraversableParentView(this);
334 336
335 Layout(); 337 Layout();
336 } 338 }
337 339
338 void ArcCustomNotificationView::SetSurface(exo::NotificationSurface* surface) { 340 void ArcNotificationContentView::SetSurface(exo::NotificationSurface* surface) {
339 if (surface_ == surface) 341 if (surface_ == surface)
340 return; 342 return;
341 343
342 // Reset |floating_control_buttons_widget_| when |surface_| is changed. 344 // Reset |floating_control_buttons_widget_| when |surface_| is changed.
343 floating_control_buttons_widget_.reset(); 345 floating_control_buttons_widget_.reset();
344 control_buttons_view_ = nullptr; 346 control_buttons_view_ = nullptr;
345 settings_button_ = nullptr; 347 settings_button_ = nullptr;
346 close_button_.reset(); 348 close_button_.reset();
347 349
348 if (surface_ && surface_->window()) { 350 if (surface_ && surface_->window()) {
349 surface_->window()->RemoveObserver(this); 351 surface_->window()->RemoveObserver(this);
350 surface_->window()->RemovePreTargetHandler(event_forwarder_.get()); 352 surface_->window()->RemovePreTargetHandler(event_forwarder_.get());
351 } 353 }
352 354
353 surface_ = surface; 355 surface_ = surface;
354 356
355 if (surface_ && surface_->window()) { 357 if (surface_ && surface_->window()) {
356 surface_->window()->AddObserver(this); 358 surface_->window()->AddObserver(this);
357 surface_->window()->AddPreTargetHandler(event_forwarder_.get()); 359 surface_->window()->AddPreTargetHandler(event_forwarder_.get());
358 360
359 MaybeCreateFloatingControlButtons(); 361 MaybeCreateFloatingControlButtons();
360 362
361 if (GetWidget()) 363 if (GetWidget())
362 AttachSurface(); 364 AttachSurface();
363 } 365 }
364 } 366 }
365 367
366 void ArcCustomNotificationView::UpdatePreferredSize() { 368 void ArcNotificationContentView::UpdatePreferredSize() {
367 gfx::Size preferred_size; 369 gfx::Size preferred_size;
368 if (surface_) 370 if (surface_)
369 preferred_size = surface_->GetSize(); 371 preferred_size = surface_->GetSize();
370 else if (item_) 372 else if (item_)
371 preferred_size = item_->GetSnapshot().size(); 373 preferred_size = item_->GetSnapshot().size();
372 374
373 if (preferred_size.IsEmpty()) 375 if (preferred_size.IsEmpty())
374 return; 376 return;
375 377
376 if (preferred_size.width() != message_center::kNotificationWidth) { 378 if (preferred_size.width() != message_center::kNotificationWidth) {
377 const float scale = static_cast<float>(message_center::kNotificationWidth) / 379 const float scale = static_cast<float>(message_center::kNotificationWidth) /
378 preferred_size.width(); 380 preferred_size.width();
379 preferred_size.SetSize(message_center::kNotificationWidth, 381 preferred_size.SetSize(message_center::kNotificationWidth,
380 preferred_size.height() * scale); 382 preferred_size.height() * scale);
381 } 383 }
382 384
383 SetPreferredSize(preferred_size); 385 SetPreferredSize(preferred_size);
384 } 386 }
385 387
386 void ArcCustomNotificationView::UpdateControlButtonsVisibility() { 388 void ArcNotificationContentView::UpdateControlButtonsVisibility() {
387 if (!surface_) 389 if (!surface_)
388 return; 390 return;
389 391
390 // TODO(edcourtney, yhanada): Creating the floating control widget here is not 392 // TODO(edcourtney, yhanada): Creating the floating control widget here is not
391 // correct. This function may be called during the destruction of 393 // correct. This function may be called during the destruction of
392 // |floating_control_buttons_widget_|. This can lead to memory corruption. 394 // |floating_control_buttons_widget_|. This can lead to memory corruption.
393 // Rather than creating it here, we should fix the behaviour of OnMouseExited 395 // Rather than creating it here, we should fix the behaviour of OnMouseExited
394 // and OnMouseEntered for ARC notifications in MessageCenterView. See 396 // and OnMouseEntered for ARC notifications in MessageCenterView. See
395 // crbug.com/714587 and crbug.com/709862. 397 // crbug.com/714587 and crbug.com/709862.
396 if (!floating_control_buttons_widget_) { 398 if (!floating_control_buttons_widget_) {
397 // This may update |floating_control_buttons_widget_|. 399 // This may update |floating_control_buttons_widget_|.
398 MaybeCreateFloatingControlButtons(); 400 MaybeCreateFloatingControlButtons();
399 if (!floating_control_buttons_widget_) 401 if (!floating_control_buttons_widget_)
400 return; 402 return;
401 } 403 }
402 404
403 const bool target_visiblity = 405 const bool target_visiblity =
404 IsMouseHovered() || (close_button_ && close_button_->HasFocus()) || 406 IsMouseHovered() || (close_button_ && close_button_->HasFocus()) ||
405 (settings_button_ && settings_button_->HasFocus()); 407 (settings_button_ && settings_button_->HasFocus());
406 if (target_visiblity == floating_control_buttons_widget_->IsVisible()) 408 if (target_visiblity == floating_control_buttons_widget_->IsVisible())
407 return; 409 return;
408 410
409 if (target_visiblity) 411 if (target_visiblity)
410 floating_control_buttons_widget_->Show(); 412 floating_control_buttons_widget_->Show();
411 else 413 else
412 floating_control_buttons_widget_->Hide(); 414 floating_control_buttons_widget_->Hide();
413 } 415 }
414 416
415 void ArcCustomNotificationView::UpdatePinnedState() { 417 void ArcNotificationContentView::UpdatePinnedState() {
416 if (!item_) 418 if (!item_)
417 return; 419 return;
418 420
419 if (item_->GetPinned() && close_button_) { 421 if (item_->GetPinned() && close_button_) {
420 control_buttons_view_->RemoveChildView(close_button_.get()); 422 control_buttons_view_->RemoveChildView(close_button_.get());
421 close_button_.reset(); 423 close_button_.reset();
422 Layout(); 424 Layout();
423 } else if (!item_->GetPinned() && !close_button_) { 425 } else if (!item_->GetPinned() && !close_button_) {
424 CreateCloseButton(); 426 CreateCloseButton();
425 Layout(); 427 Layout();
426 } 428 }
427 } 429 }
428 430
429 void ArcCustomNotificationView::UpdateSnapshot() { 431 void ArcNotificationContentView::UpdateSnapshot() {
430 // Bail if we have a |surface_| because it controls the sizes and paints UI. 432 // Bail if we have a |surface_| because it controls the sizes and paints UI.
431 if (surface_) 433 if (surface_)
432 return; 434 return;
433 435
434 UpdatePreferredSize(); 436 UpdatePreferredSize();
435 SchedulePaint(); 437 SchedulePaint();
436 } 438 }
437 439
438 void ArcCustomNotificationView::AttachSurface() { 440 void ArcNotificationContentView::AttachSurface() {
439 if (!GetWidget()) 441 if (!GetWidget())
440 return; 442 return;
441 443
442 UpdatePreferredSize(); 444 UpdatePreferredSize();
443 Attach(surface_->window()); 445 Attach(surface_->window());
444 446
445 // The texture for this window can be placed at subpixel position 447 // The texture for this window can be placed at subpixel position
446 // with fractional scale factor. Force to align it at the pixel 448 // with fractional scale factor. Force to align it at the pixel
447 // boundary here, and when layout is updated in Layout(). 449 // boundary here, and when layout is updated in Layout().
448 ash::wm::SnapWindowToPixelBoundary(surface_->window()); 450 ash::wm::SnapWindowToPixelBoundary(surface_->window());
449 451
450 // Creates slide helper after this view is added to its parent. 452 // Creates slide helper after this view is added to its parent.
451 slide_helper_.reset(new SlideHelper(this)); 453 slide_helper_.reset(new SlideHelper(this));
452 454
453 // Invokes Update() in case surface is attached during a slide. 455 // Invokes Update() in case surface is attached during a slide.
454 slide_helper_->Update(); 456 slide_helper_->Update();
455 457
456 // Updates pinned state to create or destroy the floating close button 458 // Updates pinned state to create or destroy the floating close button
457 // after |surface_| is attached to a widget. 459 // after |surface_| is attached to a widget.
458 if (item_) 460 if (item_)
459 UpdatePinnedState(); 461 UpdatePinnedState();
460 } 462 }
461 463
462 void ArcCustomNotificationView::StartControlButtonsColorAnimation() { 464 void ArcNotificationContentView::StartControlButtonsColorAnimation() {
463 if (control_button_color_animation_) 465 if (control_button_color_animation_)
464 control_button_color_animation_->End(); 466 control_button_color_animation_->End();
465 control_button_color_animation_.reset(new gfx::LinearAnimation(this)); 467 control_button_color_animation_.reset(new gfx::LinearAnimation(this));
466 control_button_color_animation_->SetDuration(kBackgroundColorChangeDuration); 468 control_button_color_animation_->SetDuration(kBackgroundColorChangeDuration);
467 control_button_color_animation_->Start(); 469 control_button_color_animation_->Start();
468 } 470 }
469 471
470 bool ArcCustomNotificationView::ShouldUpdateControlButtonsColor() const { 472 bool ArcNotificationContentView::ShouldUpdateControlButtonsColor() const {
471 // Don't update the control button color when we are about to be destroyed. 473 // Don't update the control button color when we are about to be destroyed.
472 if (!item_) 474 if (!item_)
473 return false; 475 return false;
474 476
475 if (settings_button_ && 477 if (settings_button_ &&
476 settings_button_->background()->get_color() != 478 settings_button_->background()->get_color() !=
477 GetControlButtonBackgroundColor(item_->GetShownContents())) 479 GetControlButtonBackgroundColor(item_->GetShownContents()))
478 return true; 480 return true;
479 if (close_button_ && 481 if (close_button_ &&
480 close_button_->background()->get_color() != 482 close_button_->background()->get_color() !=
481 GetControlButtonBackgroundColor(item_->GetShownContents())) 483 GetControlButtonBackgroundColor(item_->GetShownContents()))
482 return true; 484 return true;
483 return false; 485 return false;
484 } 486 }
485 487
486 void ArcCustomNotificationView::ViewHierarchyChanged( 488 void ArcNotificationContentView::ViewHierarchyChanged(
487 const views::View::ViewHierarchyChangedDetails& details) { 489 const views::View::ViewHierarchyChangedDetails& details) {
488 views::Widget* widget = GetWidget(); 490 views::Widget* widget = GetWidget();
489 491
490 if (!details.is_add) { 492 if (!details.is_add) {
491 // Resets slide helper when this view is removed from its parent. 493 // Resets slide helper when this view is removed from its parent.
492 slide_helper_.reset(); 494 slide_helper_.reset();
493 495
494 // Bail if this view is no longer attached to a widget or native_view() has 496 // Bail if this view is no longer attached to a widget or native_view() has
495 // attached to a different widget. 497 // attached to a different widget.
496 if (!widget || (native_view() && 498 if (!widget ||
497 views::Widget::GetTopLevelWidgetForNativeView( 499 (native_view() && views::Widget::GetTopLevelWidgetForNativeView(
498 native_view()) != widget)) { 500 native_view()) != widget)) {
499 return; 501 return;
500 } 502 }
501 } 503 }
502 504
503 views::NativeViewHost::ViewHierarchyChanged(details); 505 views::NativeViewHost::ViewHierarchyChanged(details);
504 506
505 if (!widget || !surface_ || !details.is_add) 507 if (!widget || !surface_ || !details.is_add)
506 return; 508 return;
507 509
508 AttachSurface(); 510 AttachSurface();
509 } 511 }
510 512
511 void ArcCustomNotificationView::Layout() { 513 void ArcNotificationContentView::Layout() {
512 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); 514 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true);
513 515
514 views::NativeViewHost::Layout(); 516 views::NativeViewHost::Layout();
515 517
516 if (!surface_ || !GetWidget()) 518 if (!surface_ || !GetWidget())
517 return; 519 return;
518 520
519 const gfx::Rect contents_bounds = GetContentsBounds(); 521 const gfx::Rect contents_bounds = GetContentsBounds();
520 522
521 // Scale notification surface if necessary. 523 // Scale notification surface if necessary.
(...skipping 30 matching lines...) Expand all
552 message_center::kControlButtonPadding); 554 message_center::kControlButtonPadding);
553 control_buttons_bounds.set_width(buttons_width); 555 control_buttons_bounds.set_width(buttons_width);
554 control_buttons_bounds.set_height(buttons_height); 556 control_buttons_bounds.set_height(buttons_height);
555 floating_control_buttons_widget_->SetBounds(control_buttons_bounds); 557 floating_control_buttons_widget_->SetBounds(control_buttons_bounds);
556 558
557 UpdateControlButtonsVisibility(); 559 UpdateControlButtonsVisibility();
558 560
559 ash::wm::SnapWindowToPixelBoundary(surface_->window()); 561 ash::wm::SnapWindowToPixelBoundary(surface_->window());
560 } 562 }
561 563
562 void ArcCustomNotificationView::OnPaint(gfx::Canvas* canvas) { 564 void ArcNotificationContentView::OnPaint(gfx::Canvas* canvas) {
563 views::NativeViewHost::OnPaint(canvas); 565 views::NativeViewHost::OnPaint(canvas);
564 566
565 // Bail if there is a |surface_| or no item or no snapshot image. 567 // Bail if there is a |surface_| or no item or no snapshot image.
566 if (surface_ || !item_ || item_->GetSnapshot().isNull()) 568 if (surface_ || !item_ || item_->GetSnapshot().isNull())
567 return; 569 return;
568 const gfx::Rect contents_bounds = GetContentsBounds(); 570 const gfx::Rect contents_bounds = GetContentsBounds();
569 canvas->DrawImageInt(item_->GetSnapshot(), 0, 0, item_->GetSnapshot().width(), 571 canvas->DrawImageInt(item_->GetSnapshot(), 0, 0, item_->GetSnapshot().width(),
570 item_->GetSnapshot().height(), contents_bounds.x(), 572 item_->GetSnapshot().height(), contents_bounds.x(),
571 contents_bounds.y(), contents_bounds.width(), 573 contents_bounds.y(), contents_bounds.width(),
572 contents_bounds.height(), false); 574 contents_bounds.height(), false);
573 } 575 }
574 576
575 void ArcCustomNotificationView::OnMouseEntered(const ui::MouseEvent&) { 577 void ArcNotificationContentView::OnMouseEntered(const ui::MouseEvent&) {
576 UpdateControlButtonsVisibility(); 578 UpdateControlButtonsVisibility();
577 } 579 }
578 580
579 void ArcCustomNotificationView::OnMouseExited(const ui::MouseEvent&) { 581 void ArcNotificationContentView::OnMouseExited(const ui::MouseEvent&) {
580 UpdateControlButtonsVisibility(); 582 UpdateControlButtonsVisibility();
581 } 583 }
582 584
583 void ArcCustomNotificationView::OnFocus() { 585 void ArcNotificationContentView::OnFocus() {
584 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName()); 586 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName());
585 587
586 NativeViewHost::OnFocus(); 588 NativeViewHost::OnFocus();
587 static_cast<ArcNotificationView*>(parent())->OnContentFocused(); 589 static_cast<ArcNotificationView*>(parent())->OnContentFocused();
588 } 590 }
589 591
590 void ArcCustomNotificationView::OnBlur() { 592 void ArcNotificationContentView::OnBlur() {
591 if (!parent()) { 593 if (!parent()) {
592 // OnBlur may be called when this view is being removed. 594 // OnBlur may be called when this view is being removed.
593 return; 595 return;
594 } 596 }
595 597
596 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName()); 598 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName());
597 599
598 NativeViewHost::OnBlur(); 600 NativeViewHost::OnBlur();
599 static_cast<ArcNotificationView*>(parent())->OnContentBlured(); 601 static_cast<ArcNotificationView*>(parent())->OnContentBlured();
600 } 602 }
601 603
602 void ArcCustomNotificationView::ActivateToast() { 604 void ArcNotificationContentView::ActivateToast() {
603 if (message_center::ToastContentsView::kViewClassName == 605 if (message_center::ToastContentsView::kViewClassName ==
604 parent()->parent()->GetClassName()) { 606 parent()->parent()->GetClassName()) {
605 static_cast<message_center::ToastContentsView*>(parent()->parent()) 607 static_cast<message_center::ToastContentsView*>(parent()->parent())
606 ->ActivateToast(); 608 ->ActivateToast();
607 } 609 }
608 } 610 }
609 611
610 views::FocusTraversable* ArcCustomNotificationView::GetFocusTraversable() { 612 views::FocusTraversable* ArcNotificationContentView::GetFocusTraversable() {
611 if (floating_control_buttons_widget_) 613 if (floating_control_buttons_widget_)
612 return static_cast<views::internal::RootView*>( 614 return static_cast<views::internal::RootView*>(
613 floating_control_buttons_widget_->GetRootView()); 615 floating_control_buttons_widget_->GetRootView());
614 return nullptr; 616 return nullptr;
615 } 617 }
616 618
617 bool ArcCustomNotificationView::HandleAccessibleAction( 619 bool ArcNotificationContentView::HandleAccessibleAction(
618 const ui::AXActionData& action_data) { 620 const ui::AXActionData& action_data) {
619 if (item_ && action_data.action == ui::AX_ACTION_DO_DEFAULT) { 621 if (item_ && action_data.action == ui::AX_ACTION_DO_DEFAULT) {
620 item_->ToggleExpansion(); 622 item_->ToggleExpansion();
621 return true; 623 return true;
622 } 624 }
623 return false; 625 return false;
624 } 626 }
625 627
626 void ArcCustomNotificationView::ButtonPressed(views::Button* sender, 628 void ArcNotificationContentView::ButtonPressed(views::Button* sender,
627 const ui::Event& event) { 629 const ui::Event& event) {
628 if (item_ && !item_->GetPinned() && sender == close_button_.get()) { 630 if (item_ && !item_->GetPinned() && sender == close_button_.get()) {
629 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName()); 631 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName());
630 static_cast<ArcNotificationView*>(parent())->OnCloseButtonPressed(); 632 static_cast<ArcNotificationView*>(parent())->OnCloseButtonPressed();
631 } 633 }
632 if (item_ && settings_button_ && sender == settings_button_) { 634 if (item_ && settings_button_ && sender == settings_button_) {
633 item_->OpenSettings(); 635 item_->OpenSettings();
634 } 636 }
635 } 637 }
636 638
637 void ArcCustomNotificationView::OnWindowBoundsChanged( 639 void ArcNotificationContentView::OnWindowBoundsChanged(
638 aura::Window* window, 640 aura::Window* window,
639 const gfx::Rect& old_bounds, 641 const gfx::Rect& old_bounds,
640 const gfx::Rect& new_bounds) { 642 const gfx::Rect& new_bounds) {
641 if (in_layout_) 643 if (in_layout_)
642 return; 644 return;
643 645
644 UpdatePreferredSize(); 646 UpdatePreferredSize();
645 Layout(); 647 Layout();
646 } 648 }
647 649
648 void ArcCustomNotificationView::OnWindowDestroying(aura::Window* window) { 650 void ArcNotificationContentView::OnWindowDestroying(aura::Window* window) {
649 SetSurface(nullptr); 651 SetSurface(nullptr);
650 } 652 }
651 653
652 void ArcCustomNotificationView::OnItemDestroying() { 654 void ArcNotificationContentView::OnItemDestroying() {
653 item_->RemoveObserver(this); 655 item_->RemoveObserver(this);
654 item_ = nullptr; 656 item_ = nullptr;
655 657
656 // Reset |surface_| with |item_| since no one is observing the |surface_| 658 // Reset |surface_| with |item_| since no one is observing the |surface_|
657 // after |item_| is gone and this view should be removed soon. 659 // after |item_| is gone and this view should be removed soon.
658 SetSurface(nullptr); 660 SetSurface(nullptr);
659 } 661 }
660 662
661 void ArcCustomNotificationView::OnItemUpdated() { 663 void ArcNotificationContentView::OnItemUpdated() {
662 UpdatePinnedState(); 664 UpdatePinnedState();
663 UpdateSnapshot(); 665 UpdateSnapshot();
664 if (ShouldUpdateControlButtonsColor()) 666 if (ShouldUpdateControlButtonsColor())
665 StartControlButtonsColorAnimation(); 667 StartControlButtonsColorAnimation();
666 } 668 }
667 669
668 void ArcCustomNotificationView::OnNotificationSurfaceAdded( 670 void ArcNotificationContentView::OnNotificationSurfaceAdded(
669 exo::NotificationSurface* surface) { 671 exo::NotificationSurface* surface) {
670 if (surface->notification_id() != notification_key_) 672 if (surface->notification_id() != notification_key_)
671 return; 673 return;
672 674
673 SetSurface(surface); 675 SetSurface(surface);
674 } 676 }
675 677
676 void ArcCustomNotificationView::OnNotificationSurfaceRemoved( 678 void ArcNotificationContentView::OnNotificationSurfaceRemoved(
677 exo::NotificationSurface* surface) { 679 exo::NotificationSurface* surface) {
678 if (surface->notification_id() != notification_key_) 680 if (surface->notification_id() != notification_key_)
679 return; 681 return;
680 682
681 SetSurface(nullptr); 683 SetSurface(nullptr);
682 } 684 }
683 685
684 void ArcCustomNotificationView::AnimationEnded( 686 void ArcNotificationContentView::AnimationEnded(
685 const gfx::Animation* animation) { 687 const gfx::Animation* animation) {
686 DCHECK_EQ(animation, control_button_color_animation_.get()); 688 DCHECK_EQ(animation, control_button_color_animation_.get());
687 control_button_color_animation_.reset(); 689 control_button_color_animation_.reset();
688 } 690 }
689 691
690 void ArcCustomNotificationView::AnimationProgressed( 692 void ArcNotificationContentView::AnimationProgressed(
691 const gfx::Animation* animation) { 693 const gfx::Animation* animation) {
692 DCHECK_EQ(animation, control_button_color_animation_.get()); 694 DCHECK_EQ(animation, control_button_color_animation_.get());
693 695
694 if (item_) { 696 if (item_) {
695 const SkColor target = 697 const SkColor target =
696 GetControlButtonBackgroundColor(item_->GetShownContents()); 698 GetControlButtonBackgroundColor(item_->GetShownContents());
697 const SkColor start = 699 const SkColor start =
698 target == message_center::kControlButtonBackgroundColor 700 target == message_center::kControlButtonBackgroundColor
699 ? SK_ColorTRANSPARENT 701 ? SK_ColorTRANSPARENT
700 : message_center::kControlButtonBackgroundColor; 702 : message_center::kControlButtonBackgroundColor;
701 const SkColor current_color = gfx::Tween::ColorValueBetween( 703 const SkColor current_color = gfx::Tween::ColorValueBetween(
702 animation->GetCurrentValue(), start, target); 704 animation->GetCurrentValue(), start, target);
703 if (settings_button_) { 705 if (settings_button_) {
704 settings_button_->set_background( 706 settings_button_->set_background(
705 views::Background::CreateSolidBackground(current_color)); 707 views::Background::CreateSolidBackground(current_color));
706 settings_button_->SchedulePaint(); 708 settings_button_->SchedulePaint();
707 } 709 }
708 if (close_button_) { 710 if (close_button_) {
709 close_button_->set_background( 711 close_button_->set_background(
710 views::Background::CreateSolidBackground(current_color)); 712 views::Background::CreateSolidBackground(current_color));
711 close_button_->SchedulePaint(); 713 close_button_->SchedulePaint();
712 } 714 }
713 } 715 }
714 } 716 }
715 717
716 } // namespace arc 718 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698