Chromium Code Reviews| 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" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 virtual void ButtonPressed(views::Button* sender, const views::Event& event); | 48 virtual void ButtonPressed(views::Button* sender, const views::Event& event); |
| 49 | 49 |
| 50 void UpdateContent(const GURL& url, FullscreenExitBubbleType bubble_type); | 50 void UpdateContent(const GURL& url, FullscreenExitBubbleType bubble_type); |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 // views::View | 53 // views::View |
| 54 virtual void Layout(); | 54 virtual void Layout(); |
| 55 | 55 |
| 56 FullscreenExitBubbleViews* bubble_; | 56 FullscreenExitBubbleViews* bubble_; |
| 57 | 57 |
| 58 // Clickable hint text for exiting browser fullscreen mode. | 58 // Clickable hint text for exiting fullscreen mode. |
| 59 views::Link link_; | 59 views::Link link_; |
| 60 // Instruction for exiting tab fullscreen mode. | |
| 61 views::Label instruction_label_; | |
| 62 views::Label message_label_; | 60 views::Label message_label_; |
| 63 views::NativeTextButton* accept_button_; | 61 views::NativeTextButton* accept_button_; |
| 64 views::NativeTextButton* deny_button_; | 62 views::NativeTextButton* deny_button_; |
| 63 string16 browser_fullscreen_exit_text_; | |
| 65 }; | 64 }; |
| 66 | 65 |
| 67 FullscreenExitBubbleViews::FullscreenExitView::FullscreenExitView( | 66 FullscreenExitBubbleViews::FullscreenExitView::FullscreenExitView( |
| 68 FullscreenExitBubbleViews* bubble, | 67 FullscreenExitBubbleViews* bubble, |
| 69 const string16& accelerator, | 68 const string16& accelerator, |
| 70 const GURL& url, | 69 const GURL& url, |
| 71 FullscreenExitBubbleType bubble_type) | 70 FullscreenExitBubbleType bubble_type) |
| 72 : bubble_(bubble), | 71 : bubble_(bubble), |
| 73 accept_button_(NULL), | 72 accept_button_(NULL), |
| 74 deny_button_(NULL) { | 73 deny_button_(NULL) { |
| 74 #if !defined(OS_CHROMEOS) | |
| 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 | |
| 75 views::BubbleBorder* bubble_border = | 82 views::BubbleBorder* bubble_border = |
| 76 new views::BubbleBorder(views::BubbleBorder::NONE); | 83 new views::BubbleBorder(views::BubbleBorder::NONE); |
| 77 bubble_border->set_background_color(Bubble::kBackgroundColor); | 84 bubble_border->set_background_color(Bubble::kBackgroundColor); |
| 78 set_background(new views::BubbleBackground(bubble_border)); | 85 set_background(new views::BubbleBackground(bubble_border)); |
| 79 set_border(bubble_border); | 86 set_border(bubble_border); |
| 80 set_focusable(false); | 87 set_focusable(false); |
| 81 | 88 |
| 82 message_label_.set_parent_owned(false); | 89 message_label_.set_parent_owned(false); |
| 83 message_label_.SetFont(ResourceBundle::GetSharedInstance().GetFont( | 90 message_label_.SetFont(ResourceBundle::GetSharedInstance().GetFont( |
| 84 ResourceBundle::MediumFont)); | 91 ResourceBundle::MediumFont)); |
| 85 | 92 |
| 86 instruction_label_.set_parent_owned(false); | |
| 87 instruction_label_.SetText(bubble_->GetInstructionText()); | |
| 88 instruction_label_.SetFont(ResourceBundle::GetSharedInstance().GetFont( | |
| 89 ResourceBundle::MediumFont)); | |
| 90 | |
| 91 link_.set_parent_owned(false); | 93 link_.set_parent_owned(false); |
| 92 link_.set_collapse_when_hidden(false); | 94 link_.set_collapse_when_hidden(false); |
| 93 link_.set_focusable(false); | 95 link_.set_focusable(false); |
| 94 #if !defined(OS_CHROMEOS) | |
| 95 link_.SetText( | |
| 96 l10n_util::GetStringFUTF16(IDS_EXIT_FULLSCREEN_MODE, | |
| 97 accelerator)); | |
| 98 #else | |
| 99 link_.SetText(l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE)); | |
| 100 #endif | |
| 101 link_.set_listener(bubble); | 96 link_.set_listener(bubble); |
| 102 link_.SetFont(ResourceBundle::GetSharedInstance().GetFont( | 97 link_.SetFont(ResourceBundle::GetSharedInstance().GetFont( |
| 103 ResourceBundle::MediumFont)); | 98 ResourceBundle::MediumFont)); |
| 104 link_.SetPressedColor(message_label_.enabled_color()); | 99 link_.SetPressedColor(message_label_.enabled_color()); |
| 105 link_.SetEnabledColor(message_label_.enabled_color()); | 100 link_.SetEnabledColor(message_label_.enabled_color()); |
| 106 link_.SetVisible(false); | 101 link_.SetVisible(false); |
| 107 | 102 |
| 108 link_.SetBackgroundColor(background()->get_color()); | 103 link_.SetBackgroundColor(background()->get_color()); |
| 109 message_label_.SetBackgroundColor(background()->get_color()); | 104 message_label_.SetBackgroundColor(background()->get_color()); |
| 110 instruction_label_.SetBackgroundColor(background()->get_color()); | |
| 111 AddChildView(&message_label_); | 105 AddChildView(&message_label_); |
| 112 AddChildView(&instruction_label_); | |
| 113 AddChildView(&link_); | 106 AddChildView(&link_); |
| 114 | 107 |
| 115 accept_button_ = new views::NativeTextButton( | 108 accept_button_ = new views::NativeTextButton( |
| 116 this, bubble->GetAllowButtonText()); | 109 this, bubble->GetAllowButtonText()); |
| 117 accept_button_->set_focusable(false); | 110 accept_button_->set_focusable(false); |
| 118 AddChildView(accept_button_); | 111 AddChildView(accept_button_); |
| 119 | 112 |
| 120 deny_button_ = new views::NativeTextButton(this); | 113 deny_button_ = new views::NativeTextButton(this); |
| 121 deny_button_->set_focusable(false); | 114 deny_button_->set_focusable(false); |
| 122 AddChildView(deny_button_); | 115 AddChildView(deny_button_); |
| 123 | 116 |
| 124 UpdateContent(url, bubble_type); | 117 UpdateContent(url, bubble_type); |
| 125 } | 118 } |
| 126 | 119 |
| 127 FullscreenExitBubbleViews::FullscreenExitView::~FullscreenExitView() { | 120 FullscreenExitBubbleViews::FullscreenExitView::~FullscreenExitView() { |
| 128 } | 121 } |
| 129 | 122 |
| 130 void FullscreenExitBubbleViews::FullscreenExitView::ButtonPressed( | 123 void FullscreenExitBubbleViews::FullscreenExitView::ButtonPressed( |
| 131 views::Button* sender, const views::Event& event) { | 124 views::Button* sender, const views::Event& event) { |
| 132 if (sender == accept_button_) | 125 if (sender == accept_button_) |
| 133 bubble_->Accept(); | 126 bubble_->Accept(); |
| 134 else | 127 else |
| 135 bubble_->Cancel(); | 128 bubble_->Cancel(); |
| 136 } | 129 } |
| 137 | 130 |
| 138 gfx::Size FullscreenExitBubbleViews::FullscreenExitView::GetPreferredSize() { | 131 gfx::Size FullscreenExitBubbleViews::FullscreenExitView::GetPreferredSize() { |
| 139 gfx::Size message_size(message_label_.GetPreferredSize()); | 132 gfx::Size message_size(message_label_.GetPreferredSize()); |
| 140 | 133 |
| 141 gfx::Size button_instruction_area; | 134 gfx::Size button_instruction_area; |
| 142 if (instruction_label_.IsVisible()) { | 135 if (link_.IsVisible()) { |
| 143 button_instruction_area = instruction_label_.GetPreferredSize(); | |
| 144 } else if (link_.IsVisible()) { | |
| 145 button_instruction_area = link_.GetPreferredSize(); | 136 button_instruction_area = link_.GetPreferredSize(); |
| 146 } else { | 137 } else { |
| 147 gfx::Size accept_size(accept_button_->GetPreferredSize()); | 138 gfx::Size accept_size(accept_button_->GetPreferredSize()); |
| 148 gfx::Size deny_size(deny_button_->GetPreferredSize()); | 139 gfx::Size deny_size(deny_button_->GetPreferredSize()); |
| 149 button_instruction_area.set_height(accept_size.height()); | 140 button_instruction_area.set_height(accept_size.height()); |
| 150 button_instruction_area.set_width( | 141 button_instruction_area.set_width( |
| 151 accept_size.width() + kPaddingPx + deny_size.width()); | 142 accept_size.width() + kPaddingPx + deny_size.width()); |
| 152 } | 143 } |
| 153 | 144 |
| 154 gfx::Insets insets(GetInsets()); | 145 gfx::Insets insets(GetInsets()); |
| 155 gfx::Size result( | 146 gfx::Size result( |
| 156 message_size.width() + kMiddlePaddingPx + button_instruction_area.width(), | 147 message_size.width() + kMiddlePaddingPx + button_instruction_area.width(), |
| 157 std::max(message_size.height(), button_instruction_area.height())); | 148 std::max(message_size.height(), button_instruction_area.height())); |
| 158 result.Enlarge(insets.width() + 2 * kPaddingPx, | 149 result.Enlarge(insets.width() + 2 * kPaddingPx, |
| 159 insets.height() + 2 * kPaddingPx); | 150 insets.height() + 2 * kPaddingPx); |
| 160 return result; | 151 return result; |
| 161 } | 152 } |
| 162 | 153 |
| 163 void FullscreenExitBubbleViews::FullscreenExitView::UpdateContent( | 154 void FullscreenExitBubbleViews::FullscreenExitView::UpdateContent( |
| 164 const GURL& url, | 155 const GURL& url, |
| 165 FullscreenExitBubbleType bubble_type) { | 156 FullscreenExitBubbleType bubble_type) { |
| 166 DCHECK_NE(FEB_TYPE_NONE, bubble_type); | 157 DCHECK_NE(FEB_TYPE_NONE, bubble_type); |
| 167 | 158 |
| 168 message_label_.SetText(bubble_->GetCurrentMessageText()); | 159 message_label_.SetText(bubble_->GetCurrentMessageText()); |
| 169 if (fullscreen_bubble::ShowButtonsForType(bubble_type)) { | 160 if (fullscreen_bubble::ShowButtonsForType(bubble_type)) { |
|
Peter Kasting
2011/11/09 23:32:52
Nit: This whole block can be shortened, assuming t
| |
| 170 link_.SetVisible(false); | 161 link_.SetVisible(false); |
| 171 instruction_label_.SetVisible(false); | |
| 172 accept_button_->SetVisible(true); | 162 accept_button_->SetVisible(true); |
| 173 deny_button_->SetText(bubble_->GetCurrentDenyButtonText()); | 163 deny_button_->SetText(bubble_->GetCurrentDenyButtonText()); |
| 174 deny_button_->SetVisible(true); | 164 deny_button_->SetVisible(true); |
| 175 deny_button_->ClearMaxTextSize(); | 165 deny_button_->ClearMaxTextSize(); |
| 176 } else { | 166 } else { |
| 177 bool link_visible = | 167 if (bubble_type == FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION) |
| 178 bubble_type == FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; | 168 link_.SetText(browser_fullscreen_exit_text_); |
| 179 link_.SetVisible(link_visible); | 169 else |
| 180 instruction_label_.SetVisible(!link_visible); | 170 link_.SetText(bubble_->GetInstructionText()); |
| 171 link_.SetVisible(true); | |
| 181 accept_button_->SetVisible(false); | 172 accept_button_->SetVisible(false); |
| 182 deny_button_->SetVisible(false); | 173 deny_button_->SetVisible(false); |
| 183 } | 174 } |
| 184 } | 175 } |
| 185 | 176 |
| 186 void FullscreenExitBubbleViews::FullscreenExitView::Layout() { | 177 void FullscreenExitBubbleViews::FullscreenExitView::Layout() { |
| 187 // TODO(thakis): Use a LayoutManager instead of doing manual layout. | 178 // TODO(thakis): Use a LayoutManager instead of doing manual layout. |
| 188 gfx::Size message_size(message_label_.GetPreferredSize()); | 179 gfx::Size message_size(message_label_.GetPreferredSize()); |
| 189 gfx::Insets insets(GetInsets()); | 180 gfx::Insets insets(GetInsets()); |
| 190 int x = insets.left() + kPaddingPx; | 181 int x = insets.left() + kPaddingPx; |
| 191 int inner_height = height() - insets.height(); | 182 int inner_height = height() - insets.height(); |
| 192 | 183 |
| 193 message_label_.SetBounds( | 184 message_label_.SetBounds( |
| 194 x, insets.top() + (inner_height - message_size.height()) / 2, | 185 x, insets.top() + (inner_height - message_size.height()) / 2, |
| 195 message_size.width(), message_size.height()); | 186 message_size.width(), message_size.height()); |
| 196 x += message_size.width() + kMiddlePaddingPx; | 187 x += message_size.width() + kMiddlePaddingPx; |
| 197 | 188 |
| 198 if (instruction_label_.IsVisible()) { | 189 if (link_.IsVisible()) { |
| 199 gfx::Size instruction_size(instruction_label_.GetPreferredSize()); | |
| 200 instruction_label_.SetBounds( | |
| 201 x, insets.top() + (inner_height - instruction_size.height()) / 2, | |
| 202 instruction_size.width(), instruction_size.height()); | |
| 203 } else if (link_.IsVisible()) { | |
| 204 gfx::Size link_size(link_.GetPreferredSize()); | 190 gfx::Size link_size(link_.GetPreferredSize()); |
| 205 link_.SetBounds(x, insets.top() + (inner_height - link_size.height()) / 2, | 191 link_.SetBounds(x, insets.top() + (inner_height - link_size.height()) / 2, |
| 206 link_size.width(), link_size.height()); | 192 link_size.width(), link_size.height()); |
| 207 } else { | 193 } else { |
| 208 gfx::Size accept_size(accept_button_->GetPreferredSize()); | 194 gfx::Size accept_size(accept_button_->GetPreferredSize()); |
| 209 gfx::Size deny_size(deny_button_->GetPreferredSize()); | 195 gfx::Size deny_size(deny_button_->GetPreferredSize()); |
| 210 int button_y = insets.top() + (inner_height - accept_size.height()) / 2; | 196 int button_y = insets.top() + (inner_height - accept_size.height()) / 2; |
| 211 accept_button_->SetBounds( | 197 accept_button_->SetBounds( |
| 212 x, button_y, accept_size.width(), accept_size.height()); | 198 x, button_y, accept_size.width(), accept_size.height()); |
| 213 x += accept_size.width() + kPaddingPx; | 199 x += accept_size.width() + kPaddingPx; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 size.set_height(size.height() - popup_bottom + y_offset); | 347 size.set_height(size.height() - popup_bottom + y_offset); |
| 362 origin.set_y(origin.y() - y_offset); | 348 origin.set_y(origin.y() - y_offset); |
| 363 } | 349 } |
| 364 return gfx::Rect(origin, size); | 350 return gfx::Rect(origin, size); |
| 365 } | 351 } |
| 366 | 352 |
| 367 void FullscreenExitBubbleViews::StartWatchingMouseIfNecessary() { | 353 void FullscreenExitBubbleViews::StartWatchingMouseIfNecessary() { |
| 368 if (!fullscreen_bubble::ShowButtonsForType(bubble_type_)) | 354 if (!fullscreen_bubble::ShowButtonsForType(bubble_type_)) |
| 369 StartWatchingMouse(); | 355 StartWatchingMouse(); |
| 370 } | 356 } |
| OLD | NEW |