| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "ui/gfx/skia_util.h" | 22 #include "ui/gfx/skia_util.h" |
| 23 #include "ui/gfx/text_elider.h" | 23 #include "ui/gfx/text_elider.h" |
| 24 #include "ui/message_center/message_center.h" | 24 #include "ui/message_center/message_center.h" |
| 25 #include "ui/message_center/message_center_style.h" | 25 #include "ui/message_center/message_center_style.h" |
| 26 #include "ui/message_center/notification.h" | 26 #include "ui/message_center/notification.h" |
| 27 #include "ui/message_center/notification_types.h" | 27 #include "ui/message_center/notification_types.h" |
| 28 #include "ui/message_center/views/bounded_label.h" | 28 #include "ui/message_center/views/bounded_label.h" |
| 29 #include "ui/message_center/views/constants.h" | 29 #include "ui/message_center/views/constants.h" |
| 30 #include "ui/message_center/views/message_center_controller.h" | 30 #include "ui/message_center/views/message_center_controller.h" |
| 31 #include "ui/message_center/views/notification_button.h" | 31 #include "ui/message_center/views/notification_button.h" |
| 32 #include "ui/message_center/views/notification_control_buttons_view.h" |
| 32 #include "ui/message_center/views/padded_button.h" | 33 #include "ui/message_center/views/padded_button.h" |
| 33 #include "ui/message_center/views/proportional_image_view.h" | 34 #include "ui/message_center/views/proportional_image_view.h" |
| 34 #include "ui/native_theme/native_theme.h" | 35 #include "ui/native_theme/native_theme.h" |
| 35 #include "ui/strings/grit/ui_strings.h" | 36 #include "ui/strings/grit/ui_strings.h" |
| 36 #include "ui/views/background.h" | 37 #include "ui/views/background.h" |
| 37 #include "ui/views/border.h" | 38 #include "ui/views/border.h" |
| 38 #include "ui/views/controls/button/image_button.h" | 39 #include "ui/views/controls/button/image_button.h" |
| 39 #include "ui/views/controls/image_view.h" | 40 #include "ui/views/controls/image_view.h" |
| 40 #include "ui/views/controls/label.h" | 41 #include "ui/views/controls/label.h" |
| 41 #include "ui/views/controls/progress_bar.h" | 42 #include "ui/views/controls/progress_bar.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 for (int i = 0; i < child_count(); ++i) | 134 for (int i = 0; i < child_count(); ++i) |
| 134 child_at(i)->SetVisible(visible); | 135 child_at(i)->SetVisible(visible); |
| 135 } | 136 } |
| 136 | 137 |
| 137 } // namespace | 138 } // namespace |
| 138 | 139 |
| 139 namespace message_center { | 140 namespace message_center { |
| 140 | 141 |
| 141 // NotificationView //////////////////////////////////////////////////////////// | 142 // NotificationView //////////////////////////////////////////////////////////// |
| 142 | 143 |
| 143 views::View* NotificationView::TargetForRect(views::View* root, | |
| 144 const gfx::Rect& rect) { | |
| 145 CHECK_EQ(root, this); | |
| 146 | |
| 147 // TODO(tdanderson): Modify this function to support rect-based event | |
| 148 // targeting. Using the center point of |rect| preserves this function's | |
| 149 // expected behavior for the time being. | |
| 150 gfx::Point point = rect.CenterPoint(); | |
| 151 | |
| 152 // Want to return this for underlying views, otherwise GetCursor is not | |
| 153 // called. But buttons are exceptions, they'll have their own event handlings. | |
| 154 std::vector<views::View*> buttons(action_buttons_.begin(), | |
| 155 action_buttons_.end()); | |
| 156 if (settings_button_view_) | |
| 157 buttons.push_back(settings_button_view_); | |
| 158 if (close_button()) | |
| 159 buttons.push_back(close_button()); | |
| 160 | |
| 161 for (size_t i = 0; i < buttons.size(); ++i) { | |
| 162 gfx::Point point_in_child = point; | |
| 163 ConvertPointToTarget(this, buttons[i], &point_in_child); | |
| 164 if (buttons[i]->HitTestPoint(point_in_child)) | |
| 165 return buttons[i]->GetEventHandlerForPoint(point_in_child); | |
| 166 } | |
| 167 | |
| 168 return root; | |
| 169 } | |
| 170 | |
| 171 void NotificationView::CreateOrUpdateViews(const Notification& notification) { | 144 void NotificationView::CreateOrUpdateViews(const Notification& notification) { |
| 172 CreateOrUpdateTitleView(notification); | 145 CreateOrUpdateTitleView(notification); |
| 173 CreateOrUpdateMessageView(notification); | 146 CreateOrUpdateMessageView(notification); |
| 174 CreateOrUpdateProgressBarView(notification); | 147 CreateOrUpdateProgressBarView(notification); |
| 175 CreateOrUpdateListItemViews(notification); | 148 CreateOrUpdateListItemViews(notification); |
| 176 CreateOrUpdateIconView(notification); | 149 CreateOrUpdateIconView(notification); |
| 177 CreateOrUpdateSmallIconView(notification); | 150 CreateOrUpdateSmallIconView(notification); |
| 178 CreateOrUpdateImageView(notification); | 151 CreateOrUpdateImageView(notification); |
| 179 CreateOrUpdateContextMessageView(notification); | 152 CreateOrUpdateContextMessageView(notification); |
| 180 CreateOrUpdateSettingsButtonView(notification); | |
| 181 CreateOrUpdateActionButtonViews(notification); | 153 CreateOrUpdateActionButtonViews(notification); |
| 182 } | 154 } |
| 183 | 155 |
| 184 NotificationView::NotificationView(MessageCenterController* controller, | 156 NotificationView::NotificationView(MessageCenterController* controller, |
| 185 const Notification& notification) | 157 const Notification& notification) |
| 186 : MessageView(controller, notification), | 158 : MessageView(controller, notification), |
| 187 clickable_(notification.clickable()) { | 159 clickable_(notification.clickable()) { |
| 188 // Create the top_view_, which collects into a vertical box all content | 160 // Create the top_view_, which collects into a vertical box all content |
| 189 // at the top of the notification (to the right of the icon) except for the | 161 // at the top of the notification (to the right of the icon) except for the |
| 190 // close button. | 162 // close button. |
| 191 top_view_ = new views::View(); | 163 top_view_ = new views::View(); |
| 192 top_view_->SetLayoutManager( | 164 top_view_->SetLayoutManager( |
| 193 new views::BoxLayout(views::BoxLayout::kVertical)); | 165 new views::BoxLayout(views::BoxLayout::kVertical)); |
| 194 top_view_->SetBorder( | 166 top_view_->SetBorder( |
| 195 MakeEmptyBorder(kTextTopPadding - 8, 0, kTextBottomPadding - 5, 0)); | 167 MakeEmptyBorder(kTextTopPadding - 8, 0, kTextBottomPadding - 5, 0)); |
| 196 AddChildView(top_view_); | 168 AddChildView(top_view_); |
| 197 // Create the bottom_view_, which collects into a vertical box all content | 169 // Create the bottom_view_, which collects into a vertical box all content |
| 198 // below the notification icon. | 170 // below the notification icon. |
| 199 bottom_view_ = new views::View(); | 171 bottom_view_ = new views::View(); |
| 200 bottom_view_->SetLayoutManager( | 172 bottom_view_->SetLayoutManager( |
| 201 new views::BoxLayout(views::BoxLayout::kVertical)); | 173 new views::BoxLayout(views::BoxLayout::kVertical)); |
| 202 AddChildView(bottom_view_); | 174 AddChildView(bottom_view_); |
| 203 | 175 |
| 176 control_buttons_view_ = new NotificationControlButtonsView(this); |
| 177 AddChildView(control_buttons_view_); |
| 178 |
| 204 views::ImageView* small_image_view = new views::ImageView(); | 179 views::ImageView* small_image_view = new views::ImageView(); |
| 205 small_image_view->SetImageSize(gfx::Size(kSmallImageSize, kSmallImageSize)); | 180 small_image_view->SetImageSize(gfx::Size(kSmallImageSize, kSmallImageSize)); |
| 206 small_image_view->set_owned_by_client(); | 181 small_image_view->set_owned_by_client(); |
| 207 small_image_view_.reset(small_image_view); | 182 small_image_view_.reset(small_image_view); |
| 208 | 183 |
| 209 CreateOrUpdateViews(notification); | 184 CreateOrUpdateViews(notification); |
| 210 | 185 |
| 211 // Put together the different content and control views. Layering those allows | 186 // Put together the different content and control views. Layering those allows |
| 212 // for proper layout logic and it also allows the close button and small | 187 // for proper layout logic and it also allows the control buttons and small |
| 213 // image to overlap the content as needed to provide large enough click and | 188 // image to overlap the content as needed to provide large enough click and |
| 214 // touch areas (<http://crbug.com/168822> and <http://crbug.com/168856>). | 189 // touch areas (<http://crbug.com/168822> and <http://crbug.com/168856>). |
| 215 AddChildView(small_image_view_.get()); | 190 AddChildView(small_image_view_.get()); |
| 216 CreateOrUpdateCloseButtonView(notification); | 191 UpdateControlButtonsVisibilityWithNotification(notification); |
| 217 | 192 |
| 218 SetEventTargeter( | 193 SetEventTargeter( |
| 219 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); | 194 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
| 220 set_notify_enter_exit_on_child(true); | 195 set_notify_enter_exit_on_child(true); |
| 221 } | 196 } |
| 222 | 197 |
| 223 NotificationView::~NotificationView() { | 198 NotificationView::~NotificationView() { |
| 224 } | 199 } |
| 225 | 200 |
| 226 gfx::Size NotificationView::CalculatePreferredSize() const { | 201 gfx::Size NotificationView::CalculatePreferredSize() const { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 message_view_->SetLineLimit(GetMessageLineLimit(title_lines, width())); | 259 message_view_->SetLineLimit(GetMessageLineLimit(title_lines, width())); |
| 285 | 260 |
| 286 // Top views. | 261 // Top views. |
| 287 int top_height = top_view_->GetHeightForWidth(content_width); | 262 int top_height = top_view_->GetHeightForWidth(content_width); |
| 288 top_view_->SetBounds(insets.left(), insets.top(), content_width, top_height); | 263 top_view_->SetBounds(insets.left(), insets.top(), content_width, top_height); |
| 289 | 264 |
| 290 // Icon. | 265 // Icon. |
| 291 icon_view_->SetBounds(insets.left(), insets.top(), kNotificationIconSize, | 266 icon_view_->SetBounds(insets.left(), insets.top(), kNotificationIconSize, |
| 292 kNotificationIconSize); | 267 kNotificationIconSize); |
| 293 | 268 |
| 294 // Settings & Bottom views. | 269 // Control buttons (close and settings buttons). |
| 295 int bottom_y = insets.top() + std::max(top_height, kNotificationIconSize); | 270 gfx::Rect control_buttons_bounds(content_bounds); |
| 296 int bottom_height = bottom_view_->GetHeightForWidth(content_width); | 271 int buttons_width = control_buttons_view_->GetPreferredSize().width(); |
| 297 | 272 int buttons_height = control_buttons_view_->GetPreferredSize().height(); |
| 298 if (settings_button_view_) { | 273 control_buttons_bounds.set_x(control_buttons_bounds.right() - buttons_width - |
| 299 const gfx::Size settings_size(settings_button_view_->GetPreferredSize()); | 274 message_center::kControlButtonPadding); |
| 300 int marginFromRight = settings_size.width() + kControlButtonPadding; | 275 control_buttons_bounds.set_y(control_buttons_bounds.y() + |
| 301 if (close_button_) | 276 message_center::kControlButtonPadding); |
| 302 marginFromRight += close_button_->GetPreferredSize().width(); | 277 control_buttons_bounds.set_width(buttons_width); |
| 303 gfx::Rect settings_rect(insets.left() + content_width - marginFromRight, | 278 control_buttons_bounds.set_height(buttons_height); |
| 304 GetContentsBounds().y() + kControlButtonPadding, | 279 control_buttons_view_->SetBoundsRect(control_buttons_bounds); |
| 305 settings_size.width(), settings_size.height()); | |
| 306 settings_button_view_->SetBoundsRect(settings_rect); | |
| 307 } | |
| 308 | |
| 309 // Close button. | |
| 310 if (close_button_) { | |
| 311 gfx::Rect content_bounds = GetContentsBounds(); | |
| 312 gfx::Size close_size(close_button_->GetPreferredSize()); | |
| 313 gfx::Rect close_rect( | |
| 314 content_bounds.right() - close_size.width() - kControlButtonPadding, | |
| 315 content_bounds.y() + kControlButtonPadding, close_size.width(), | |
| 316 close_size.height()); | |
| 317 close_button_->SetBoundsRect(close_rect); | |
| 318 } | |
| 319 | 280 |
| 320 // Small icon. | 281 // Small icon. |
| 321 gfx::Size small_image_size(small_image_view_->GetPreferredSize()); | 282 gfx::Size small_image_size(small_image_view_->GetPreferredSize()); |
| 322 gfx::Rect small_image_rect(small_image_size); | 283 gfx::Rect small_image_rect(small_image_size); |
| 323 small_image_rect.set_origin(gfx::Point( | 284 small_image_rect.set_origin(gfx::Point( |
| 324 content_bounds.right() - small_image_size.width() - kSmallImagePadding, | 285 content_bounds.right() - small_image_size.width() - kSmallImagePadding, |
| 325 content_bounds.bottom() - small_image_size.height() - | 286 content_bounds.bottom() - small_image_size.height() - |
| 326 kSmallImagePadding)); | 287 kSmallImagePadding)); |
| 327 small_image_view_->SetBoundsRect(small_image_rect); | 288 small_image_view_->SetBoundsRect(small_image_rect); |
| 328 | 289 |
| 290 // Bottom views. |
| 291 int bottom_y = insets.top() + std::max(top_height, kNotificationIconSize); |
| 292 int bottom_height = bottom_view_->GetHeightForWidth(content_width); |
| 329 bottom_view_->SetBounds(insets.left(), bottom_y, | 293 bottom_view_->SetBounds(insets.left(), bottom_y, |
| 330 content_width, bottom_height); | 294 content_width, bottom_height); |
| 331 } | 295 } |
| 332 | 296 |
| 333 void NotificationView::OnFocus() { | 297 void NotificationView::OnFocus() { |
| 334 MessageView::OnFocus(); | 298 MessageView::OnFocus(); |
| 335 ScrollRectToVisible(GetLocalBounds()); | 299 ScrollRectToVisible(GetLocalBounds()); |
| 336 } | 300 } |
| 337 | 301 |
| 338 void NotificationView::ScrollRectToVisible(const gfx::Rect& rect) { | 302 void NotificationView::ScrollRectToVisible(const gfx::Rect& rect) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 361 void NotificationView::OnMouseExited(const ui::MouseEvent& event) { | 325 void NotificationView::OnMouseExited(const ui::MouseEvent& event) { |
| 362 MessageView::OnMouseExited(event); | 326 MessageView::OnMouseExited(event); |
| 363 UpdateControlButtonsVisibility(); | 327 UpdateControlButtonsVisibility(); |
| 364 } | 328 } |
| 365 | 329 |
| 366 void NotificationView::UpdateWithNotification( | 330 void NotificationView::UpdateWithNotification( |
| 367 const Notification& notification) { | 331 const Notification& notification) { |
| 368 MessageView::UpdateWithNotification(notification); | 332 MessageView::UpdateWithNotification(notification); |
| 369 | 333 |
| 370 CreateOrUpdateViews(notification); | 334 CreateOrUpdateViews(notification); |
| 371 CreateOrUpdateCloseButtonView(notification); | 335 UpdateControlButtonsVisibilityWithNotification(notification); |
| 372 Layout(); | 336 Layout(); |
| 373 SchedulePaint(); | 337 SchedulePaint(); |
| 374 } | 338 } |
| 375 | 339 |
| 376 void NotificationView::ButtonPressed(views::Button* sender, | 340 void NotificationView::ButtonPressed(views::Button* sender, |
| 377 const ui::Event& event) { | 341 const ui::Event& event) { |
| 378 // Certain operations can cause |this| to be destructed, so copy the members | 342 // Certain operations can cause |this| to be destructed, so copy the members |
| 379 // we send to other parts of the code. | 343 // we send to other parts of the code. |
| 380 // TODO(dewittj): Remove this hack. | 344 // TODO(dewittj): Remove this hack. |
| 381 std::string id(notification_id()); | 345 std::string id(notification_id()); |
| 382 | 346 |
| 383 if (close_button_ && sender == close_button_.get()) { | |
| 384 // Warning: This causes the NotificationView itself to be deleted, so don't | |
| 385 // do anything afterwards. | |
| 386 OnCloseButtonPressed(); | |
| 387 return; | |
| 388 } | |
| 389 | |
| 390 if (sender == settings_button_view_) { | |
| 391 OnSettingsButtonPressed(); | |
| 392 return; | |
| 393 } | |
| 394 | |
| 395 // See if the button pressed was an action button. | 347 // See if the button pressed was an action button. |
| 396 for (size_t i = 0; i < action_buttons_.size(); ++i) { | 348 for (size_t i = 0; i < action_buttons_.size(); ++i) { |
| 397 if (sender == action_buttons_[i]) { | 349 if (sender == action_buttons_[i]) { |
| 398 controller()->ClickOnNotificationButton(id, i); | 350 controller()->ClickOnNotificationButton(id, i); |
| 399 return; | 351 return; |
| 400 } | 352 } |
| 401 } | 353 } |
| 354 |
| 355 NOTREACHED(); |
| 402 } | 356 } |
| 403 | 357 |
| 404 bool NotificationView::IsCloseButtonFocused() const { | 358 bool NotificationView::IsCloseButtonFocused() const { |
| 405 if (!close_button_) | 359 return control_buttons_view_->IsCloseButtonFocused(); |
| 406 return false; | |
| 407 | |
| 408 const views::FocusManager* focus_manager = GetFocusManager(); | |
| 409 return focus_manager && | |
| 410 focus_manager->GetFocusedView() == close_button_.get(); | |
| 411 } | 360 } |
| 412 | 361 |
| 413 void NotificationView::RequestFocusOnCloseButton() { | 362 void NotificationView::RequestFocusOnCloseButton() { |
| 414 if (close_button_) | 363 control_buttons_view_->RequestFocusOnCloseButton(); |
| 415 close_button_->RequestFocus(); | |
| 416 } | 364 } |
| 417 | 365 |
| 418 void NotificationView::CreateOrUpdateTitleView( | 366 void NotificationView::CreateOrUpdateTitleView( |
| 419 const Notification& notification) { | 367 const Notification& notification) { |
| 420 if (notification.title().empty()) { | 368 if (notification.title().empty()) { |
| 421 // Deletion will also remove |title_view_| from its parent. | 369 // Deletion will also remove |title_view_| from its parent. |
| 422 delete title_view_; | 370 delete title_view_; |
| 423 title_view_ = nullptr; | 371 title_view_ = nullptr; |
| 424 return; | 372 return; |
| 425 } | 373 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 context_message_view_->SetLineHeight(kMessageLineHeight); | 464 context_message_view_->SetLineHeight(kMessageLineHeight); |
| 517 context_message_view_->SetColors(message_center::kDimTextColor, | 465 context_message_view_->SetColors(message_center::kDimTextColor, |
| 518 kContextTextBackgroundColor); | 466 kContextTextBackgroundColor); |
| 519 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); | 467 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); |
| 520 top_view_->AddChildView(context_message_view_); | 468 top_view_->AddChildView(context_message_view_); |
| 521 } else { | 469 } else { |
| 522 context_message_view_->SetText(message); | 470 context_message_view_->SetText(message); |
| 523 } | 471 } |
| 524 } | 472 } |
| 525 | 473 |
| 526 void NotificationView::CreateOrUpdateSettingsButtonView( | |
| 527 const Notification& notification) { | |
| 528 delete settings_button_view_; | |
| 529 settings_button_view_ = nullptr; | |
| 530 | |
| 531 if (!settings_button_view_ && notification.delegate() && | |
| 532 notification.delegate()->ShouldDisplaySettingsButton()) { | |
| 533 PaddedButton* settings = new PaddedButton(this); | |
| 534 settings->SetImage(views::Button::STATE_NORMAL, GetSettingsIcon()); | |
| 535 settings->SetAccessibleName(l10n_util::GetStringUTF16( | |
| 536 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); | |
| 537 settings->SetTooltipText(l10n_util::GetStringUTF16( | |
| 538 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); | |
| 539 settings_button_view_ = settings; | |
| 540 AddChildView(settings_button_view_); | |
| 541 } | |
| 542 UpdateControlButtonsVisibility(); | |
| 543 } | |
| 544 | |
| 545 void NotificationView::CreateOrUpdateProgressBarView( | 474 void NotificationView::CreateOrUpdateProgressBarView( |
| 546 const Notification& notification) { | 475 const Notification& notification) { |
| 547 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { | 476 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { |
| 548 // Deletion will also remove |progress_bar_view_| from its parent. | 477 // Deletion will also remove |progress_bar_view_| from its parent. |
| 549 delete progress_bar_view_; | 478 delete progress_bar_view_; |
| 550 progress_bar_view_ = nullptr; | 479 progress_bar_view_ = nullptr; |
| 551 return; | 480 return; |
| 552 } | 481 } |
| 553 | 482 |
| 554 DCHECK(top_view_); | 483 DCHECK(top_view_); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 if (new_buttons) { | 615 if (new_buttons) { |
| 687 Layout(); | 616 Layout(); |
| 688 views::Widget* widget = GetWidget(); | 617 views::Widget* widget = GetWidget(); |
| 689 if (widget != NULL) { | 618 if (widget != NULL) { |
| 690 widget->SetSize(widget->GetContentsView()->GetPreferredSize()); | 619 widget->SetSize(widget->GetContentsView()->GetPreferredSize()); |
| 691 GetWidget()->SynthesizeMouseMoveEvent(); | 620 GetWidget()->SynthesizeMouseMoveEvent(); |
| 692 } | 621 } |
| 693 } | 622 } |
| 694 } | 623 } |
| 695 | 624 |
| 696 void NotificationView::CreateOrUpdateCloseButtonView( | 625 void NotificationView::UpdateControlButtonsVisibilityWithNotification( |
| 697 const Notification& notification) { | 626 const Notification& notification) { |
| 698 if (!notification.pinned() && !close_button_) { | 627 control_buttons_view_->ShowSettingsButton( |
| 699 close_button_ = base::MakeUnique<PaddedButton>(this); | 628 notification.delegate() && |
| 700 close_button_->SetImage(views::Button::STATE_NORMAL, GetCloseIcon()); | 629 notification.delegate()->ShouldDisplaySettingsButton()); |
| 701 close_button_->SetAccessibleName(l10n_util::GetStringUTF16( | 630 control_buttons_view_->ShowCloseButton(!notification.pinned()); |
| 702 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); | 631 UpdateControlButtonsVisibility(); |
| 703 close_button_->SetTooltipText(l10n_util::GetStringUTF16( | |
| 704 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP)); | |
| 705 close_button_->set_owned_by_client(); | |
| 706 AddChildView(close_button_.get()); | |
| 707 UpdateControlButtonsVisibility(); | |
| 708 } else if (notification.pinned() && close_button_) { | |
| 709 close_button_.reset(); | |
| 710 } | |
| 711 } | 632 } |
| 712 | 633 |
| 713 void NotificationView::UpdateControlButtonsVisibility() { | 634 void NotificationView::UpdateControlButtonsVisibility() { |
| 714 #if defined(OS_CHROMEOS) | 635 #if defined(OS_CHROMEOS) |
| 715 // On Chrome OS, the settings button and the close button are shown only when | 636 // On Chrome OS, the settings button and the close button are shown when: |
| 716 // the mouse is hovering on the notification. | 637 // (1) the mouse is hovering on the notification. |
| 638 // (2) the focus is on the control buttons. |
| 717 const bool target_visibility = | 639 const bool target_visibility = |
| 718 IsMouseHovered() || HasFocus() || | 640 IsMouseHovered() || HasFocus() || |
| 719 (close_button_ && | 641 control_buttons_view_->IsCloseButtonFocused() || |
| 720 (close_button_->HasFocus() || close_button_->IsMouseHovered())) || | 642 control_buttons_view_->IsSettingsButtonFocused(); |
| 721 (settings_button_view_ && (settings_button_view_->HasFocus() || | |
| 722 settings_button_view_->IsMouseHovered())); | |
| 723 #else | 643 #else |
| 724 // On non Chrome OS, the settings button and the close button are always | 644 // On non Chrome OS, the settings button and the close button are always |
| 725 // shown. | 645 // shown. |
| 726 const bool target_visibility = true; | 646 const bool target_visibility = true; |
| 727 #endif | 647 #endif |
| 728 | 648 |
| 729 if (close_button_) { | 649 control_buttons_view_->SetVisible(target_visibility); |
| 730 if (target_visibility != close_button_->visible()) | |
| 731 close_button_->SetVisible(target_visibility); | |
| 732 } | |
| 733 | |
| 734 if (settings_button_view_) { | |
| 735 if (target_visibility != settings_button_view_->visible()) | |
| 736 settings_button_view_->SetVisible(target_visibility); | |
| 737 } | |
| 738 } | 650 } |
| 739 | 651 |
| 740 int NotificationView::GetMessageLineLimit(int title_lines, int width) const { | 652 int NotificationView::GetMessageLineLimit(int title_lines, int width) const { |
| 741 // Image notifications require that the image must be kept flush against | 653 // Image notifications require that the image must be kept flush against |
| 742 // their icons, but we can allow more text if no image. | 654 // their icons, but we can allow more text if no image. |
| 743 int effective_title_lines = std::max(0, title_lines - 1); | 655 int effective_title_lines = std::max(0, title_lines - 1); |
| 744 int line_reduction_from_title = (image_view_ ? 1 : 2) * effective_title_lines; | 656 int line_reduction_from_title = (image_view_ ? 1 : 2) * effective_title_lines; |
| 745 if (!image_view_) { | 657 if (!image_view_) { |
| 746 // Title lines are counted as twice as big as message lines for the purpose | 658 // Title lines are counted as twice as big as message lines for the purpose |
| 747 // of this calculation. | 659 // of this calculation. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 772 | 684 |
| 773 return message_line_limit; | 685 return message_line_limit; |
| 774 } | 686 } |
| 775 | 687 |
| 776 int NotificationView::GetMessageHeight(int width, int limit) const { | 688 int NotificationView::GetMessageHeight(int width, int limit) const { |
| 777 return message_view_ ? | 689 return message_view_ ? |
| 778 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 690 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
| 779 } | 691 } |
| 780 | 692 |
| 781 } // namespace message_center | 693 } // namespace message_center |
| OLD | NEW |