| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/notification_view.h" | 5 #include "ui/message_center/views/notification_view.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "ui/views/background.h" | 32 #include "ui/views/background.h" |
| 33 #include "ui/views/border.h" | 33 #include "ui/views/border.h" |
| 34 #include "ui/views/controls/button/image_button.h" | 34 #include "ui/views/controls/button/image_button.h" |
| 35 #include "ui/views/controls/image_view.h" | 35 #include "ui/views/controls/image_view.h" |
| 36 #include "ui/views/controls/label.h" | 36 #include "ui/views/controls/label.h" |
| 37 #include "ui/views/controls/progress_bar.h" | 37 #include "ui/views/controls/progress_bar.h" |
| 38 #include "ui/views/layout/box_layout.h" | 38 #include "ui/views/layout/box_layout.h" |
| 39 #include "ui/views/layout/fill_layout.h" | 39 #include "ui/views/layout/fill_layout.h" |
| 40 #include "ui/views/native_cursor.h" | 40 #include "ui/views/native_cursor.h" |
| 41 #include "ui/views/painter.h" | 41 #include "ui/views/painter.h" |
| 42 #include "ui/views/view_targeter.h" |
| 42 #include "ui/views/widget/widget.h" | 43 #include "ui/views/widget/widget.h" |
| 43 | 44 |
| 44 namespace { | 45 namespace { |
| 45 | 46 |
| 46 // Dimensions. | 47 // Dimensions. |
| 47 const int kProgressBarWidth = message_center::kNotificationWidth - | 48 const int kProgressBarWidth = message_center::kNotificationWidth - |
| 48 message_center::kTextLeftPadding - message_center::kTextRightPadding; | 49 message_center::kTextLeftPadding - message_center::kTextRightPadding; |
| 49 const int kProgressBarBottomPadding = 0; | 50 const int kProgressBarBottomPadding = 0; |
| 50 | 51 |
| 51 // static | 52 // static |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 283 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 283 // Don't create shadows for notification toasts on linux wih aura. | 284 // Don't create shadows for notification toasts on linux wih aura. |
| 284 if (top_level) | 285 if (top_level) |
| 285 return notification_view; | 286 return notification_view; |
| 286 #endif | 287 #endif |
| 287 | 288 |
| 288 notification_view->CreateShadowBorder(); | 289 notification_view->CreateShadowBorder(); |
| 289 return notification_view; | 290 return notification_view; |
| 290 } | 291 } |
| 291 | 292 |
| 293 views::View* NotificationView::TargetForRect(views::View* root, |
| 294 const gfx::Rect& rect) { |
| 295 CHECK_EQ(root, this); |
| 296 |
| 297 // TODO(tdanderson): Modify this function to support rect-based event |
| 298 // targeting. Using the center point of |rect| preserves this function's |
| 299 // expected behavior for the time being. |
| 300 gfx::Point point = rect.CenterPoint(); |
| 301 |
| 302 // Want to return this for underlying views, otherwise GetCursor is not |
| 303 // called. But buttons are exceptions, they'll have their own event handlings. |
| 304 std::vector<views::View*> buttons(action_buttons_.begin(), |
| 305 action_buttons_.end()); |
| 306 buttons.push_back(close_button()); |
| 307 |
| 308 for (size_t i = 0; i < buttons.size(); ++i) { |
| 309 gfx::Point point_in_child = point; |
| 310 ConvertPointToTarget(this, buttons[i], &point_in_child); |
| 311 if (buttons[i]->HitTestPoint(point_in_child)) |
| 312 return buttons[i]->GetEventHandlerForPoint(point_in_child); |
| 313 } |
| 314 |
| 315 return root; |
| 316 } |
| 317 |
| 292 void NotificationView::CreateOrUpdateViews(const Notification& notification) { | 318 void NotificationView::CreateOrUpdateViews(const Notification& notification) { |
| 293 CreateOrUpdateTitleView(notification); | 319 CreateOrUpdateTitleView(notification); |
| 294 CreateOrUpdateMessageView(notification); | 320 CreateOrUpdateMessageView(notification); |
| 295 CreateOrUpdateContextMessageView(notification); | 321 CreateOrUpdateContextMessageView(notification); |
| 296 CreateOrUpdateProgressBarView(notification); | 322 CreateOrUpdateProgressBarView(notification); |
| 297 CreateOrUpdateListItemViews(notification); | 323 CreateOrUpdateListItemViews(notification); |
| 298 CreateOrUpdateIconView(notification); | 324 CreateOrUpdateIconView(notification); |
| 299 CreateOrUpdateImageView(notification); | 325 CreateOrUpdateImageView(notification); |
| 300 CreateOrUpdateActionButtonViews(notification); | 326 CreateOrUpdateActionButtonViews(notification); |
| 301 } | 327 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 374 |
| 349 CreateOrUpdateViews(notification); | 375 CreateOrUpdateViews(notification); |
| 350 | 376 |
| 351 // Put together the different content and control views. Layering those allows | 377 // Put together the different content and control views. Layering those allows |
| 352 // for proper layout logic and it also allows the close button and small | 378 // for proper layout logic and it also allows the close button and small |
| 353 // image to overlap the content as needed to provide large enough click and | 379 // image to overlap the content as needed to provide large enough click and |
| 354 // touch areas (<http://crbug.com/168822> and <http://crbug.com/168856>). | 380 // touch areas (<http://crbug.com/168822> and <http://crbug.com/168856>). |
| 355 AddChildView(small_image()); | 381 AddChildView(small_image()); |
| 356 AddChildView(close_button()); | 382 AddChildView(close_button()); |
| 357 SetAccessibleName(notification); | 383 SetAccessibleName(notification); |
| 384 |
| 385 SetEventTargeter( |
| 386 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
| 358 } | 387 } |
| 359 | 388 |
| 360 NotificationView::~NotificationView() { | 389 NotificationView::~NotificationView() { |
| 361 } | 390 } |
| 362 | 391 |
| 363 gfx::Size NotificationView::GetPreferredSize() const { | 392 gfx::Size NotificationView::GetPreferredSize() const { |
| 364 int top_width = top_view_->GetPreferredSize().width() + | 393 int top_width = top_view_->GetPreferredSize().width() + |
| 365 icon_view_->GetPreferredSize().width(); | 394 icon_view_->GetPreferredSize().width(); |
| 366 int bottom_width = bottom_view_->GetPreferredSize().width(); | 395 int bottom_width = bottom_view_->GetPreferredSize().width(); |
| 367 int preferred_width = std::max(top_width, bottom_width) + GetInsets().width(); | 396 int preferred_width = std::max(top_width, bottom_width) + GetInsets().width(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 MessageView::OnFocus(); | 463 MessageView::OnFocus(); |
| 435 ScrollRectToVisible(GetLocalBounds()); | 464 ScrollRectToVisible(GetLocalBounds()); |
| 436 } | 465 } |
| 437 | 466 |
| 438 void NotificationView::ScrollRectToVisible(const gfx::Rect& rect) { | 467 void NotificationView::ScrollRectToVisible(const gfx::Rect& rect) { |
| 439 // Notification want to show the whole notification when a part of it (like | 468 // Notification want to show the whole notification when a part of it (like |
| 440 // a button) gets focused. | 469 // a button) gets focused. |
| 441 views::View::ScrollRectToVisible(GetLocalBounds()); | 470 views::View::ScrollRectToVisible(GetLocalBounds()); |
| 442 } | 471 } |
| 443 | 472 |
| 444 views::View* NotificationView::GetEventHandlerForRect(const gfx::Rect& rect) { | |
| 445 // TODO(tdanderson): Modify this function to support rect-based event | |
| 446 // targeting. Using the center point of |rect| preserves this function's | |
| 447 // expected behavior for the time being. | |
| 448 gfx::Point point = rect.CenterPoint(); | |
| 449 | |
| 450 // Want to return this for underlying views, otherwise GetCursor is not | |
| 451 // called. But buttons are exceptions, they'll have their own event handlings. | |
| 452 std::vector<views::View*> buttons(action_buttons_.begin(), | |
| 453 action_buttons_.end()); | |
| 454 buttons.push_back(close_button()); | |
| 455 | |
| 456 for (size_t i = 0; i < buttons.size(); ++i) { | |
| 457 gfx::Point point_in_child = point; | |
| 458 ConvertPointToTarget(this, buttons[i], &point_in_child); | |
| 459 if (buttons[i]->HitTestPoint(point_in_child)) | |
| 460 return buttons[i]->GetEventHandlerForPoint(point_in_child); | |
| 461 } | |
| 462 | |
| 463 return this; | |
| 464 } | |
| 465 | |
| 466 gfx::NativeCursor NotificationView::GetCursor(const ui::MouseEvent& event) { | 473 gfx::NativeCursor NotificationView::GetCursor(const ui::MouseEvent& event) { |
| 467 if (!clickable_ || !controller_->HasClickedListener(notification_id())) | 474 if (!clickable_ || !controller_->HasClickedListener(notification_id())) |
| 468 return views::View::GetCursor(event); | 475 return views::View::GetCursor(event); |
| 469 | 476 |
| 470 return views::GetNativeHandCursor(); | 477 return views::GetNativeHandCursor(); |
| 471 } | 478 } |
| 472 | 479 |
| 473 void NotificationView::UpdateWithNotification( | 480 void NotificationView::UpdateWithNotification( |
| 474 const Notification& notification) { | 481 const Notification& notification) { |
| 475 MessageView::UpdateWithNotification(notification); | 482 MessageView::UpdateWithNotification(notification); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 | 785 |
| 779 return message_line_limit; | 786 return message_line_limit; |
| 780 } | 787 } |
| 781 | 788 |
| 782 int NotificationView::GetMessageHeight(int width, int limit) const { | 789 int NotificationView::GetMessageHeight(int width, int limit) const { |
| 783 return message_view_ ? | 790 return message_view_ ? |
| 784 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 791 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
| 785 } | 792 } |
| 786 | 793 |
| 787 } // namespace message_center | 794 } // namespace message_center |
| OLD | NEW |