| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/fullscreen_exit_bubble_views.h" | 5 #include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/ui/views/bubble/bubble.h" | 10 #include "chrome/browser/ui/views/bubble/bubble.h" |
| 11 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
| 12 #include "grit/ui_strings.h" |
| 12 #include "ui/base/animation/slide_animation.h" | 13 #include "ui/base/animation/slide_animation.h" |
| 13 #include "ui/base/keycodes/keyboard_codes.h" | 14 #include "ui/base/keycodes/keyboard_codes.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/canvas_skia.h" | 17 #include "ui/gfx/canvas_skia.h" |
| 17 #include "ui/gfx/screen.h" | 18 #include "ui/gfx/screen.h" |
| 18 #include "views/bubble/bubble_border.h" | 19 #include "views/bubble/bubble_border.h" |
| 19 #include "views/controls/button/text_button.h" | 20 #include "views/controls/button/text_button.h" |
| 20 #include "views/controls/link.h" | 21 #include "views/controls/link.h" |
| 21 #include "views/widget/widget.h" | 22 #include "views/widget/widget.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 50 void UpdateContent(const GURL& url, FullscreenExitBubbleType bubble_type); | 51 void UpdateContent(const GURL& url, FullscreenExitBubbleType bubble_type); |
| 51 | 52 |
| 52 private: | 53 private: |
| 53 // views::View | 54 // views::View |
| 54 virtual void Layout(); | 55 virtual void Layout(); |
| 55 | 56 |
| 56 FullscreenExitBubbleViews* bubble_; | 57 FullscreenExitBubbleViews* bubble_; |
| 57 | 58 |
| 58 // Clickable hint text for exiting fullscreen mode. | 59 // Clickable hint text for exiting fullscreen mode. |
| 59 views::Link link_; | 60 views::Link link_; |
| 61 // Instruction for exiting mouse lock. |
| 62 views::Label mouse_lock_exit_instruction_; |
| 63 // Informational label: 'www.foo.com has gone fullscreen'. |
| 60 views::Label message_label_; | 64 views::Label message_label_; |
| 61 views::NativeTextButton* accept_button_; | 65 views::NativeTextButton* accept_button_; |
| 62 views::NativeTextButton* deny_button_; | 66 views::NativeTextButton* deny_button_; |
| 63 string16 browser_fullscreen_exit_text_; | 67 const string16 browser_fullscreen_exit_accelerator_; |
| 64 }; | 68 }; |
| 65 | 69 |
| 66 FullscreenExitBubbleViews::FullscreenExitView::FullscreenExitView( | 70 FullscreenExitBubbleViews::FullscreenExitView::FullscreenExitView( |
| 67 FullscreenExitBubbleViews* bubble, | 71 FullscreenExitBubbleViews* bubble, |
| 68 const string16& accelerator, | 72 const string16& accelerator, |
| 69 const GURL& url, | 73 const GURL& url, |
| 70 FullscreenExitBubbleType bubble_type) | 74 FullscreenExitBubbleType bubble_type) |
| 71 : bubble_(bubble), | 75 : bubble_(bubble), |
| 72 accept_button_(NULL), | 76 accept_button_(NULL), |
| 73 deny_button_(NULL) { | 77 deny_button_(NULL), |
| 74 #if !defined(OS_CHROMEOS) | 78 browser_fullscreen_exit_accelerator_(accelerator) { |
| 75 browser_fullscreen_exit_text_ = | |
| 76 l10n_util::GetStringFUTF16(IDS_EXIT_FULLSCREEN_MODE, accelerator); | |
| 77 #else | |
| 78 browser_fullscreen_exit_text_ = | |
| 79 l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE); | |
| 80 #endif | |
| 81 | |
| 82 views::BubbleBorder* bubble_border = | 79 views::BubbleBorder* bubble_border = |
| 83 new views::BubbleBorder(views::BubbleBorder::NONE); | 80 new views::BubbleBorder(views::BubbleBorder::NONE); |
| 84 bubble_border->set_background_color(Bubble::kBackgroundColor); | 81 bubble_border->set_background_color(Bubble::kBackgroundColor); |
| 85 set_background(new views::BubbleBackground(bubble_border)); | 82 set_background(new views::BubbleBackground(bubble_border)); |
| 86 set_border(bubble_border); | 83 set_border(bubble_border); |
| 87 set_focusable(false); | 84 set_focusable(false); |
| 88 | 85 |
| 89 message_label_.set_parent_owned(false); | 86 message_label_.set_parent_owned(false); |
| 90 message_label_.SetFont(ResourceBundle::GetSharedInstance().GetFont( | 87 message_label_.SetFont(ResourceBundle::GetSharedInstance().GetFont( |
| 91 ResourceBundle::MediumFont)); | 88 ResourceBundle::MediumFont)); |
| 92 | 89 |
| 90 mouse_lock_exit_instruction_.set_parent_owned(false); |
| 91 mouse_lock_exit_instruction_.SetText(bubble_->GetInstructionText()); |
| 92 mouse_lock_exit_instruction_.SetFont( |
| 93 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); |
| 94 |
| 93 link_.set_parent_owned(false); | 95 link_.set_parent_owned(false); |
| 94 link_.set_collapse_when_hidden(false); | 96 link_.set_collapse_when_hidden(false); |
| 95 link_.set_focusable(false); | 97 link_.set_focusable(false); |
| 98 #if defined(OS_CHROMEOS) |
| 99 // On CrOS, the link text doesn't change, since it doesn't show the shortcut. |
| 100 link_.SetText(l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE)); |
| 101 #endif |
| 96 link_.set_listener(bubble); | 102 link_.set_listener(bubble); |
| 97 link_.SetFont(ResourceBundle::GetSharedInstance().GetFont( | 103 link_.SetFont(ResourceBundle::GetSharedInstance().GetFont( |
| 98 ResourceBundle::MediumFont)); | 104 ResourceBundle::MediumFont)); |
| 99 link_.SetPressedColor(message_label_.enabled_color()); | 105 link_.SetPressedColor(message_label_.enabled_color()); |
| 100 link_.SetEnabledColor(message_label_.enabled_color()); | 106 link_.SetEnabledColor(message_label_.enabled_color()); |
| 101 link_.SetVisible(false); | 107 link_.SetVisible(false); |
| 102 | 108 |
| 103 link_.SetBackgroundColor(background()->get_color()); | 109 link_.SetBackgroundColor(background()->get_color()); |
| 104 message_label_.SetBackgroundColor(background()->get_color()); | 110 message_label_.SetBackgroundColor(background()->get_color()); |
| 111 mouse_lock_exit_instruction_.SetBackgroundColor(background()->get_color()); |
| 105 AddChildView(&message_label_); | 112 AddChildView(&message_label_); |
| 113 AddChildView(&mouse_lock_exit_instruction_); |
| 106 AddChildView(&link_); | 114 AddChildView(&link_); |
| 107 | 115 |
| 108 accept_button_ = new views::NativeTextButton( | 116 accept_button_ = new views::NativeTextButton( |
| 109 this, bubble->GetAllowButtonText()); | 117 this, bubble->GetAllowButtonText()); |
| 110 accept_button_->set_focusable(false); | 118 accept_button_->set_focusable(false); |
| 111 AddChildView(accept_button_); | 119 AddChildView(accept_button_); |
| 112 | 120 |
| 113 deny_button_ = new views::NativeTextButton(this); | 121 deny_button_ = new views::NativeTextButton(this); |
| 114 deny_button_->set_focusable(false); | 122 deny_button_->set_focusable(false); |
| 115 AddChildView(deny_button_); | 123 AddChildView(deny_button_); |
| 116 | 124 |
| 117 UpdateContent(url, bubble_type); | 125 UpdateContent(url, bubble_type); |
| 118 } | 126 } |
| 119 | 127 |
| 120 FullscreenExitBubbleViews::FullscreenExitView::~FullscreenExitView() { | 128 FullscreenExitBubbleViews::FullscreenExitView::~FullscreenExitView() { |
| 121 } | 129 } |
| 122 | 130 |
| 123 void FullscreenExitBubbleViews::FullscreenExitView::ButtonPressed( | 131 void FullscreenExitBubbleViews::FullscreenExitView::ButtonPressed( |
| 124 views::Button* sender, const views::Event& event) { | 132 views::Button* sender, const views::Event& event) { |
| 125 if (sender == accept_button_) | 133 if (sender == accept_button_) |
| 126 bubble_->Accept(); | 134 bubble_->Accept(); |
| 127 else | 135 else |
| 128 bubble_->Cancel(); | 136 bubble_->Cancel(); |
| 129 } | 137 } |
| 130 | 138 |
| 131 gfx::Size FullscreenExitBubbleViews::FullscreenExitView::GetPreferredSize() { | 139 gfx::Size FullscreenExitBubbleViews::FullscreenExitView::GetPreferredSize() { |
| 132 gfx::Size message_size(message_label_.GetPreferredSize()); | 140 gfx::Size message_size(message_label_.GetPreferredSize()); |
| 133 | 141 |
| 134 gfx::Size button_instruction_area; | 142 gfx::Size button_instruction_area; |
| 135 if (link_.IsVisible()) { | 143 if (mouse_lock_exit_instruction_.IsVisible()) { |
| 144 button_instruction_area = mouse_lock_exit_instruction_.GetPreferredSize(); |
| 145 } else if (link_.IsVisible()) { |
| 136 button_instruction_area = link_.GetPreferredSize(); | 146 button_instruction_area = link_.GetPreferredSize(); |
| 137 } else { | 147 } else { |
| 138 gfx::Size accept_size(accept_button_->GetPreferredSize()); | 148 gfx::Size accept_size(accept_button_->GetPreferredSize()); |
| 139 gfx::Size deny_size(deny_button_->GetPreferredSize()); | 149 gfx::Size deny_size(deny_button_->GetPreferredSize()); |
| 140 button_instruction_area.set_height(accept_size.height()); | 150 button_instruction_area.set_height(accept_size.height()); |
| 141 button_instruction_area.set_width( | 151 button_instruction_area.set_width( |
| 142 accept_size.width() + kPaddingPx + deny_size.width()); | 152 accept_size.width() + kPaddingPx + deny_size.width()); |
| 143 } | 153 } |
| 144 | 154 |
| 145 gfx::Insets insets(GetInsets()); | 155 gfx::Insets insets(GetInsets()); |
| 146 gfx::Size result( | 156 gfx::Size result( |
| 147 message_size.width() + kMiddlePaddingPx + button_instruction_area.width(), | 157 message_size.width() + kMiddlePaddingPx + button_instruction_area.width(), |
| 148 std::max(message_size.height(), button_instruction_area.height())); | 158 std::max(message_size.height(), button_instruction_area.height())); |
| 149 result.Enlarge(insets.width() + 2 * kPaddingPx, | 159 result.Enlarge(insets.width() + 2 * kPaddingPx, |
| 150 insets.height() + 2 * kPaddingPx); | 160 insets.height() + 2 * kPaddingPx); |
| 151 return result; | 161 return result; |
| 152 } | 162 } |
| 153 | 163 |
| 154 void FullscreenExitBubbleViews::FullscreenExitView::UpdateContent( | 164 void FullscreenExitBubbleViews::FullscreenExitView::UpdateContent( |
| 155 const GURL& url, | 165 const GURL& url, |
| 156 FullscreenExitBubbleType bubble_type) { | 166 FullscreenExitBubbleType bubble_type) { |
| 157 DCHECK_NE(FEB_TYPE_NONE, bubble_type); | 167 DCHECK_NE(FEB_TYPE_NONE, bubble_type); |
| 158 | 168 |
| 159 message_label_.SetText(bubble_->GetCurrentMessageText()); | 169 message_label_.SetText(bubble_->GetCurrentMessageText()); |
| 160 if (fullscreen_bubble::ShowButtonsForType(bubble_type)) { | 170 if (fullscreen_bubble::ShowButtonsForType(bubble_type)) { |
| 161 link_.SetVisible(false); | 171 link_.SetVisible(false); |
| 172 mouse_lock_exit_instruction_.SetVisible(false); |
| 162 accept_button_->SetVisible(true); | 173 accept_button_->SetVisible(true); |
| 163 deny_button_->SetText(bubble_->GetCurrentDenyButtonText()); | 174 deny_button_->SetText(bubble_->GetCurrentDenyButtonText()); |
| 164 deny_button_->SetVisible(true); | 175 deny_button_->SetVisible(true); |
| 165 deny_button_->ClearMaxTextSize(); | 176 deny_button_->ClearMaxTextSize(); |
| 166 } else { | 177 } else { |
| 167 if (bubble_type == FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION) | 178 bool link_visible = true; |
| 168 link_.SetText(browser_fullscreen_exit_text_); | 179 string16 accelerator; |
| 169 else | 180 if (bubble_type == FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION) { |
| 170 link_.SetText(bubble_->GetInstructionText()); | 181 accelerator = browser_fullscreen_exit_accelerator_; |
| 171 link_.SetVisible(true); | 182 } else if (bubble_type == FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION) { |
| 183 accelerator = l10n_util::GetStringUTF16(IDS_APP_ESC_KEY); |
| 184 } else { |
| 185 link_visible = false; |
| 186 } |
| 187 #if !defined(OS_CHROMEOS) |
| 188 if (link_visible) { |
| 189 link_.SetText( |
| 190 l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE) + |
| 191 UTF8ToUTF16(" ") + |
| 192 l10n_util::GetStringFUTF16(IDS_EXIT_FULLSCREEN_MODE_ACCELERATOR, |
| 193 accelerator)); |
| 194 } |
| 195 #endif |
| 196 link_.SetVisible(link_visible); |
| 197 mouse_lock_exit_instruction_.SetVisible(!link_visible); |
| 172 accept_button_->SetVisible(false); | 198 accept_button_->SetVisible(false); |
| 173 deny_button_->SetVisible(false); | 199 deny_button_->SetVisible(false); |
| 174 } | 200 } |
| 175 } | 201 } |
| 176 | 202 |
| 177 void FullscreenExitBubbleViews::FullscreenExitView::Layout() { | 203 void FullscreenExitBubbleViews::FullscreenExitView::Layout() { |
| 178 // TODO(thakis): Use a LayoutManager instead of doing manual layout. | 204 // TODO(thakis): Use a LayoutManager instead of doing manual layout. |
| 179 gfx::Size message_size(message_label_.GetPreferredSize()); | 205 gfx::Size message_size(message_label_.GetPreferredSize()); |
| 180 gfx::Insets insets(GetInsets()); | 206 gfx::Insets insets(GetInsets()); |
| 181 int x = insets.left() + kPaddingPx; | 207 int x = insets.left() + kPaddingPx; |
| 182 int inner_height = height() - insets.height(); | 208 int inner_height = height() - insets.height(); |
| 183 | 209 |
| 184 message_label_.SetBounds( | 210 message_label_.SetBounds( |
| 185 x, insets.top() + (inner_height - message_size.height()) / 2, | 211 x, insets.top() + (inner_height - message_size.height()) / 2, |
| 186 message_size.width(), message_size.height()); | 212 message_size.width(), message_size.height()); |
| 187 x += message_size.width() + kMiddlePaddingPx; | 213 x += message_size.width() + kMiddlePaddingPx; |
| 188 | 214 |
| 189 if (link_.IsVisible()) { | 215 if (mouse_lock_exit_instruction_.IsVisible()) { |
| 216 gfx::Size instruction_size(mouse_lock_exit_instruction_.GetPreferredSize()); |
| 217 mouse_lock_exit_instruction_.SetBounds( |
| 218 x, insets.top() + (inner_height - instruction_size.height()) / 2, |
| 219 instruction_size.width(), instruction_size.height()); |
| 220 } else if (link_.IsVisible()) { |
| 190 gfx::Size link_size(link_.GetPreferredSize()); | 221 gfx::Size link_size(link_.GetPreferredSize()); |
| 191 link_.SetBounds(x, insets.top() + (inner_height - link_size.height()) / 2, | 222 link_.SetBounds(x, insets.top() + (inner_height - link_size.height()) / 2, |
| 192 link_size.width(), link_size.height()); | 223 link_size.width(), link_size.height()); |
| 193 } else { | 224 } else { |
| 194 gfx::Size accept_size(accept_button_->GetPreferredSize()); | 225 gfx::Size accept_size(accept_button_->GetPreferredSize()); |
| 195 gfx::Size deny_size(deny_button_->GetPreferredSize()); | 226 gfx::Size deny_size(deny_button_->GetPreferredSize()); |
| 196 int button_y = insets.top() + (inner_height - accept_size.height()) / 2; | 227 int button_y = insets.top() + (inner_height - accept_size.height()) / 2; |
| 197 accept_button_->SetBounds( | 228 accept_button_->SetBounds( |
| 198 x, button_y, accept_size.width(), accept_size.height()); | 229 x, button_y, accept_size.width(), accept_size.height()); |
| 199 x += accept_size.width() + kPaddingPx; | 230 x += accept_size.width() + kPaddingPx; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 size.set_height(size.height() - popup_bottom + y_offset); | 378 size.set_height(size.height() - popup_bottom + y_offset); |
| 348 origin.set_y(origin.y() - y_offset); | 379 origin.set_y(origin.y() - y_offset); |
| 349 } | 380 } |
| 350 return gfx::Rect(origin, size); | 381 return gfx::Rect(origin, size); |
| 351 } | 382 } |
| 352 | 383 |
| 353 void FullscreenExitBubbleViews::StartWatchingMouseIfNecessary() { | 384 void FullscreenExitBubbleViews::StartWatchingMouseIfNecessary() { |
| 354 if (!fullscreen_bubble::ShowButtonsForType(bubble_type_)) | 385 if (!fullscreen_bubble::ShowButtonsForType(bubble_type_)) |
| 355 StartWatchingMouse(); | 386 StartWatchingMouse(); |
| 356 } | 387 } |
| OLD | NEW |