Chromium Code Reviews| 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 "chrome/browser/ui/views/exclusive_access_bubble_views.h" | 5 #include "chrome/browser/ui/views/exclusive_access_bubble_views.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 // ExclusiveAccessView --------------------------------------------------------- | 43 // ExclusiveAccessView --------------------------------------------------------- |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 // Space between the site info label and the buttons / link. | 47 // Space between the site info label and the buttons / link. |
| 48 const int kMiddlePaddingPx = 30; | 48 const int kMiddlePaddingPx = 30; |
| 49 | 49 |
| 50 const int kOuterPaddingHorizPx = 40; | 50 const int kOuterPaddingHorizPx = 40; |
| 51 const int kOuterPaddingVertPx = 8; | 51 const int kOuterPaddingVertPx = 8; |
| 52 | 52 |
| 53 // Partially-transparent background color. Only used with | 53 // Partially-transparent background color. |
| 54 // IsSimplifiedFullscreenUIEnabled. | |
| 55 const SkColor kBackgroundColor = SkColorSetARGB(0xcc, 0x28, 0x2c, 0x32); | 54 const SkColor kBackgroundColor = SkColorSetARGB(0xcc, 0x28, 0x2c, 0x32); |
| 56 | 55 |
| 57 class ButtonView : public views::View { | 56 class ButtonView : public views::View { |
| 58 public: | 57 public: |
| 59 ButtonView(views::ButtonListener* listener, int between_button_spacing); | 58 ButtonView(views::ButtonListener* listener, int between_button_spacing); |
| 60 ~ButtonView() override; | 59 ~ButtonView() override; |
| 61 | 60 |
| 62 views::LabelButton* accept_button() const { return accept_button_; } | 61 views::LabelButton* accept_button() const { return accept_button_; } |
| 63 views::LabelButton* deny_button() const { return deny_button_; } | 62 views::LabelButton* deny_button() const { return deny_button_; } |
| 64 | 63 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 ExclusiveAccessBubbleViews* bubble, | 223 ExclusiveAccessBubbleViews* bubble, |
| 225 const base::string16& accelerator, | 224 const base::string16& accelerator, |
| 226 const GURL& url, | 225 const GURL& url, |
| 227 ExclusiveAccessBubbleType bubble_type) | 226 ExclusiveAccessBubbleType bubble_type) |
| 228 : bubble_(bubble), | 227 : bubble_(bubble), |
| 229 link_(nullptr), | 228 link_(nullptr), |
| 230 message_label_(nullptr), | 229 message_label_(nullptr), |
| 231 button_view_(nullptr), | 230 button_view_(nullptr), |
| 232 exit_instruction_(nullptr), | 231 exit_instruction_(nullptr), |
| 233 browser_fullscreen_exit_accelerator_(accelerator) { | 232 browser_fullscreen_exit_accelerator_(accelerator) { |
| 234 views::BubbleBorder::Shadow shadow_type = views::BubbleBorder::BIG_SHADOW; | 233 const SkColor kForegroundColor = SK_ColorWHITE; |
| 235 #if defined(OS_LINUX) | |
| 236 // Use a smaller shadow on Linux (including ChromeOS) as the shadow assets can | |
| 237 // overlap each other in a fullscreen notification bubble. | |
| 238 // See http://crbug.com/462983. | |
| 239 shadow_type = views::BubbleBorder::SMALL_SHADOW; | |
| 240 #endif | |
| 241 if (ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) | |
| 242 shadow_type = views::BubbleBorder::NO_ASSETS; | |
| 243 | |
| 244 // TODO(estade): don't use this static instance. See http://crbug.com/558162 | |
| 245 ui::NativeTheme* theme = ui::NativeTheme::GetInstanceForWeb(); | |
| 246 SkColor background_color = | |
| 247 ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() | |
| 248 ? kBackgroundColor | |
| 249 : theme->GetSystemColor(ui::NativeTheme::kColorId_BubbleBackground); | |
| 250 SkColor foreground_color = | |
| 251 ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() | |
| 252 ? SK_ColorWHITE | |
| 253 : theme->GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor); | |
| 254 | 234 |
| 255 std::unique_ptr<views::BubbleBorder> bubble_border(new views::BubbleBorder( | 235 std::unique_ptr<views::BubbleBorder> bubble_border(new views::BubbleBorder( |
| 256 views::BubbleBorder::NONE, shadow_type, background_color)); | 236 views::BubbleBorder::NONE, views::BubbleBorder::NO_ASSETS, |
| 237 kBackgroundColor)); | |
| 257 set_background(new views::BubbleBackground(bubble_border.get())); | 238 set_background(new views::BubbleBackground(bubble_border.get())); |
| 258 SetBorder(std::move(bubble_border)); | 239 SetBorder(std::move(bubble_border)); |
| 259 | 240 |
| 260 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 241 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 261 const gfx::FontList& font_list = | 242 const gfx::FontList& font_list = |
| 262 rb.GetFontList(ui::ResourceBundle::MediumFont); | 243 rb.GetFontList(ui::ResourceBundle::MediumFont); |
| 263 | 244 |
| 264 if (!ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) { | 245 if (!ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) { |
| 265 message_label_ = new views::Label(base::string16(), font_list); | 246 message_label_ = new views::Label(base::string16(), font_list); |
| 266 message_label_->SetEnabledColor(foreground_color); | 247 message_label_->SetEnabledColor(kForegroundColor); |
| 267 message_label_->SetBackgroundColor(background_color); | 248 message_label_->SetBackgroundColor(kBackgroundColor); |
| 268 } | 249 } |
| 269 | 250 |
| 270 exit_instruction_ = new InstructionView(base::string16(), font_list, | 251 exit_instruction_ = new InstructionView(base::string16(), font_list, |
| 271 foreground_color, background_color); | 252 kForegroundColor, kBackgroundColor); |
| 272 | 253 |
| 273 link_ = new views::Link(); | 254 link_ = new views::Link(); |
| 274 link_->SetFocusBehavior(FocusBehavior::NEVER); | 255 link_->SetFocusBehavior(FocusBehavior::NEVER); |
| 275 #if defined(OS_CHROMEOS) | 256 #if defined(OS_CHROMEOS) |
| 276 // On CrOS, the link text doesn't change, since it doesn't show the shortcut. | 257 // On CrOS, the link text doesn't change, since it doesn't show the shortcut. |
| 277 link_->SetText(l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE)); | 258 link_->SetText(l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE)); |
| 278 #endif | 259 #endif |
| 279 link_->set_listener(this); | 260 link_->set_listener(this); |
| 280 link_->SetFontList(font_list); | 261 link_->SetFontList(font_list); |
| 281 link_->SetPressedColor(foreground_color); | 262 link_->SetPressedColor(kForegroundColor); |
| 282 link_->SetEnabledColor(foreground_color); | 263 link_->SetEnabledColor(kForegroundColor); |
| 283 link_->SetBackgroundColor(background_color); | 264 link_->SetBackgroundColor(kBackgroundColor); |
| 284 link_->SetVisible(false); | 265 link_->SetVisible(false); |
| 285 | 266 |
| 286 button_view_ = new ButtonView(this, kPaddingPx); | 267 button_view_ = new ButtonView(this, kPaddingPx); |
| 287 | 268 |
| 288 int outer_padding_horiz = kOuterPaddingHorizPx; | 269 int outer_padding_horiz = kOuterPaddingHorizPx; |
| 289 int outer_padding_vert = kOuterPaddingVertPx; | 270 int outer_padding_vert = kOuterPaddingVertPx; |
| 290 if (!ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) { | 271 if (!ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) { |
| 291 DCHECK(message_label_); | 272 DCHECK(message_label_); |
| 292 AddChildView(message_label_); | 273 AddChildView(message_label_); |
| 293 | |
| 294 outer_padding_horiz = kPaddingPx; | |
| 295 outer_padding_vert = kPaddingPx; | |
| 296 } | 274 } |
| 297 AddChildView(button_view_); | 275 AddChildView(button_view_); |
| 298 AddChildView(exit_instruction_); | 276 AddChildView(exit_instruction_); |
| 299 AddChildView(link_); | 277 AddChildView(link_); |
| 300 | 278 |
| 301 views::BoxLayout* layout = | 279 views::BoxLayout* layout = |
| 302 new views::BoxLayout(views::BoxLayout::kHorizontal, outer_padding_horiz, | 280 new views::BoxLayout(views::BoxLayout::kHorizontal, outer_padding_horiz, |
| 303 outer_padding_vert, kMiddlePaddingPx); | 281 outer_padding_vert, kMiddlePaddingPx); |
| 304 SetLayoutManager(layout); | 282 SetLayoutManager(layout); |
| 305 | 283 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 322 views::Link* link, | 300 views::Link* link, |
| 323 int event_flags) { | 301 int event_flags) { |
| 324 bubble_->ExitExclusiveAccess(); | 302 bubble_->ExitExclusiveAccess(); |
| 325 } | 303 } |
| 326 | 304 |
| 327 void ExclusiveAccessBubbleViews::ExclusiveAccessView::UpdateContent( | 305 void ExclusiveAccessBubbleViews::ExclusiveAccessView::UpdateContent( |
| 328 const GURL& url, | 306 const GURL& url, |
| 329 ExclusiveAccessBubbleType bubble_type) { | 307 ExclusiveAccessBubbleType bubble_type) { |
| 330 DCHECK_NE(EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE, bubble_type); | 308 DCHECK_NE(EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE, bubble_type); |
| 331 | 309 |
| 332 if (!ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) { | 310 bool link_visible = |
| 333 DCHECK(message_label_); | 311 !ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled(); |
| 334 message_label_->SetText(bubble_->GetCurrentMessageText()); | 312 base::string16 accelerator; |
| 313 if (bubble_type == | |
| 314 EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION || | |
| 315 bubble_type == | |
| 316 EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION) { | |
| 317 accelerator = browser_fullscreen_exit_accelerator_; | |
|
msw
2016/05/13 17:08:11
nit: init |accelerator| to this value, to simplify
Matt Giuca
2016/05/16 04:59:45
I'm not sure how that simplifies things (it just r
| |
| 318 } else { | |
| 319 accelerator = l10n_util::GetStringUTF16(IDS_APP_ESC_KEY); | |
| 320 if (bubble_type != | |
| 321 EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION) { | |
| 322 link_visible = false; | |
| 323 } | |
| 335 } | 324 } |
| 336 | |
| 337 if (exclusive_access_bubble::ShowButtonsForType(bubble_type)) { | |
| 338 link_->SetVisible(false); | |
| 339 exit_instruction_->SetVisible(false); | |
| 340 button_view_->SetVisible(true); | |
| 341 button_view_->deny_button()->SetText(bubble_->GetCurrentDenyButtonText()); | |
| 342 button_view_->deny_button()->SetMinSize(gfx::Size()); | |
| 343 button_view_->accept_button()->SetText( | |
| 344 bubble_->GetCurrentAllowButtonText()); | |
| 345 button_view_->accept_button()->SetMinSize(gfx::Size()); | |
| 346 } else { | |
| 347 bool link_visible = | |
| 348 !ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled(); | |
| 349 base::string16 accelerator; | |
| 350 if (bubble_type == | |
| 351 EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION || | |
| 352 bubble_type == | |
| 353 EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION) { | |
| 354 accelerator = browser_fullscreen_exit_accelerator_; | |
| 355 } else { | |
| 356 accelerator = l10n_util::GetStringUTF16(IDS_APP_ESC_KEY); | |
| 357 if (bubble_type != | |
| 358 EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION) { | |
| 359 link_visible = false; | |
| 360 } | |
| 361 } | |
| 362 #if !defined(OS_CHROMEOS) | 325 #if !defined(OS_CHROMEOS) |
| 363 if (link_visible) { | 326 if (link_visible) { |
| 364 link_->SetText(l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE) + | 327 link_->SetText(l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE) + |
| 365 base::UTF8ToUTF16(" ") + | 328 base::UTF8ToUTF16(" ") + |
| 366 l10n_util::GetStringFUTF16( | 329 l10n_util::GetStringFUTF16( |
| 367 IDS_EXIT_FULLSCREEN_MODE_ACCELERATOR, accelerator)); | 330 IDS_EXIT_FULLSCREEN_MODE_ACCELERATOR, accelerator)); |
| 368 } | 331 } |
| 369 #endif | 332 #endif |
| 370 link_->SetVisible(link_visible); | 333 link_->SetVisible(link_visible); |
| 371 exit_instruction_->SetText(bubble_->GetInstructionText(accelerator)); | 334 exit_instruction_->SetText(bubble_->GetInstructionText(accelerator)); |
| 372 exit_instruction_->SetVisible(!link_visible); | 335 exit_instruction_->SetVisible(!link_visible); |
| 373 button_view_->SetVisible(false); | 336 button_view_->SetVisible(false); |
|
msw
2016/05/13 17:08:11
nit: add a TODO to remove |button_view_| (and incl
Matt Giuca
2016/05/16 04:59:45
Done.
| |
| 374 } | |
| 375 } | 337 } |
| 376 | 338 |
| 377 // ExclusiveAccessBubbleViews -------------------------------------------------- | 339 // ExclusiveAccessBubbleViews -------------------------------------------------- |
| 378 | 340 |
| 379 ExclusiveAccessBubbleViews::ExclusiveAccessBubbleViews( | 341 ExclusiveAccessBubbleViews::ExclusiveAccessBubbleViews( |
| 380 ExclusiveAccessBubbleViewsContext* context, | 342 ExclusiveAccessBubbleViewsContext* context, |
| 381 const GURL& url, | 343 const GURL& url, |
| 382 ExclusiveAccessBubbleType bubble_type) | 344 ExclusiveAccessBubbleType bubble_type) |
| 383 : ExclusiveAccessBubble(context->GetExclusiveAccessManager(), | 345 : ExclusiveAccessBubble(context->GetExclusiveAccessManager(), |
| 384 url, | 346 url, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 if (popup_->IsVisible()) | 445 if (popup_->IsVisible()) |
| 484 UpdateBounds(); | 446 UpdateBounds(); |
| 485 } | 447 } |
| 486 | 448 |
| 487 views::View* ExclusiveAccessBubbleViews::GetView() { | 449 views::View* ExclusiveAccessBubbleViews::GetView() { |
| 488 return view_; | 450 return view_; |
| 489 } | 451 } |
| 490 | 452 |
| 491 ExclusiveAccessBubbleViews::AnimatedAttribute | 453 ExclusiveAccessBubbleViews::AnimatedAttribute |
| 492 ExclusiveAccessBubbleViews::ExpectedAnimationAttribute() { | 454 ExclusiveAccessBubbleViews::ExpectedAnimationAttribute() { |
| 493 return ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() || | 455 // TODO(mgiuca): Delete this function. |
| 494 bubble_view_context_->IsImmersiveModeEnabled() | 456 return ANIMATED_ATTRIBUTE_OPACITY; |
| 495 ? ANIMATED_ATTRIBUTE_OPACITY | |
| 496 : ANIMATED_ATTRIBUTE_BOUNDS; | |
| 497 } | 457 } |
| 498 | 458 |
| 499 void ExclusiveAccessBubbleViews::UpdateMouseWatcher() { | 459 void ExclusiveAccessBubbleViews::UpdateMouseWatcher() { |
| 500 bool should_watch_mouse = false; | 460 bool should_watch_mouse = false; |
| 501 if (popup_->IsVisible()) | 461 if (popup_->IsVisible()) |
| 502 should_watch_mouse = | 462 should_watch_mouse = |
| 503 !exclusive_access_bubble::ShowButtonsForType(bubble_type_); | 463 !exclusive_access_bubble::ShowButtonsForType(bubble_type_); |
| 504 else | 464 else |
| 505 should_watch_mouse = CanMouseTriggerSlideIn(); | 465 should_watch_mouse = CanMouseTriggerSlideIn(); |
| 506 | 466 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 586 // - Querying the top container height may return the height before entering | 546 // - Querying the top container height may return the height before entering |
| 587 // fullscreen because layout is disabled while entering fullscreen. | 547 // fullscreen because layout is disabled while entering fullscreen. |
| 588 // A visual glitch due to the delayed layout is avoided in immersive | 548 // A visual glitch due to the delayed layout is avoided in immersive |
| 589 // fullscreen because entering fullscreen starts with the top container | 549 // fullscreen because entering fullscreen starts with the top container |
| 590 // revealed. When revealed, the top container has the same height as before | 550 // revealed. When revealed, the top container has the same height as before |
| 591 // entering fullscreen. | 551 // entering fullscreen. |
| 592 top_container_bottom = | 552 top_container_bottom = |
| 593 bubble_view_context_->GetTopContainerBoundsInScreen().bottom(); | 553 bubble_view_context_->GetTopContainerBoundsInScreen().bottom(); |
| 594 } | 554 } |
| 595 // |desired_top| is the top of the bubble area including the shadow. | 555 // |desired_top| is the top of the bubble area including the shadow. |
| 596 int popup_top = ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() | 556 int popup_top = kSimplifiedPopupTopPx; |
|
msw
2016/05/13 17:08:11
nit: inline below.
Matt Giuca
2016/05/16 04:59:45
Done.
| |
| 597 ? kSimplifiedPopupTopPx | |
| 598 : kPopupTopPx; | |
| 599 int desired_top = popup_top - view_->border()->GetInsets().top(); | 557 int desired_top = popup_top - view_->border()->GetInsets().top(); |
| 600 int y = top_container_bottom + desired_top; | 558 int y = top_container_bottom + desired_top; |
| 601 | 559 |
| 602 if (!ignore_animation_state && | 560 if (!ignore_animation_state && |
| 603 animated_attribute_ == ANIMATED_ATTRIBUTE_BOUNDS) { | 561 animated_attribute_ == ANIMATED_ATTRIBUTE_BOUNDS) { |
| 604 int total_height = size.height() + desired_top; | 562 int total_height = size.height() + desired_top; |
| 605 int popup_bottom = animation_->CurrentValueBetween(total_height, 0); | 563 int popup_bottom = animation_->CurrentValueBetween(total_height, 0); |
| 606 int y_offset = std::min(popup_bottom, desired_top); | 564 int y_offset = std::min(popup_bottom, desired_top); |
| 607 size.set_height(size.height() - popup_bottom + y_offset); | 565 size.set_height(size.height() - popup_bottom + y_offset); |
| 608 y -= y_offset; | 566 y -= y_offset; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 646 const content::NotificationDetails& details) { | 604 const content::NotificationDetails& details) { |
| 647 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); | 605 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
| 648 UpdateForImmersiveState(); | 606 UpdateForImmersiveState(); |
| 649 } | 607 } |
| 650 | 608 |
| 651 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged( | 609 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged( |
| 652 views::Widget* widget, | 610 views::Widget* widget, |
| 653 bool visible) { | 611 bool visible) { |
| 654 UpdateMouseWatcher(); | 612 UpdateMouseWatcher(); |
| 655 } | 613 } |
| OLD | NEW |