Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: chrome/browser/ui/views/fullscreen_exit_bubble_views.cc

Issue 8528052: Fix up fullscreen exit bubble messages to suggest Esc instead of F11 where appropriate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 link_.SetText(l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE));
yzshen1 2011/11/15 21:11:29 link_'s text will be set in UpdateContent, isn't i
jeremya 2011/11/15 22:49:43 Done.
96 link_.set_listener(bubble); 99 link_.set_listener(bubble);
97 link_.SetFont(ResourceBundle::GetSharedInstance().GetFont( 100 link_.SetFont(ResourceBundle::GetSharedInstance().GetFont(
98 ResourceBundle::MediumFont)); 101 ResourceBundle::MediumFont));
99 link_.SetPressedColor(message_label_.enabled_color()); 102 link_.SetPressedColor(message_label_.enabled_color());
100 link_.SetEnabledColor(message_label_.enabled_color()); 103 link_.SetEnabledColor(message_label_.enabled_color());
101 link_.SetVisible(false); 104 link_.SetVisible(false);
102 105
103 link_.SetBackgroundColor(background()->get_color()); 106 link_.SetBackgroundColor(background()->get_color());
104 message_label_.SetBackgroundColor(background()->get_color()); 107 message_label_.SetBackgroundColor(background()->get_color());
108 mouse_lock_exit_instruction_.SetBackgroundColor(background()->get_color());
105 AddChildView(&message_label_); 109 AddChildView(&message_label_);
110 AddChildView(&mouse_lock_exit_instruction_);
106 AddChildView(&link_); 111 AddChildView(&link_);
107 112
108 accept_button_ = new views::NativeTextButton( 113 accept_button_ = new views::NativeTextButton(
109 this, bubble->GetAllowButtonText()); 114 this, bubble->GetAllowButtonText());
110 accept_button_->set_focusable(false); 115 accept_button_->set_focusable(false);
111 AddChildView(accept_button_); 116 AddChildView(accept_button_);
112 117
113 deny_button_ = new views::NativeTextButton(this); 118 deny_button_ = new views::NativeTextButton(this);
114 deny_button_->set_focusable(false); 119 deny_button_->set_focusable(false);
115 AddChildView(deny_button_); 120 AddChildView(deny_button_);
116 121
117 UpdateContent(url, bubble_type); 122 UpdateContent(url, bubble_type);
118 } 123 }
119 124
120 FullscreenExitBubbleViews::FullscreenExitView::~FullscreenExitView() { 125 FullscreenExitBubbleViews::FullscreenExitView::~FullscreenExitView() {
121 } 126 }
122 127
123 void FullscreenExitBubbleViews::FullscreenExitView::ButtonPressed( 128 void FullscreenExitBubbleViews::FullscreenExitView::ButtonPressed(
124 views::Button* sender, const views::Event& event) { 129 views::Button* sender, const views::Event& event) {
125 if (sender == accept_button_) 130 if (sender == accept_button_)
126 bubble_->Accept(); 131 bubble_->Accept();
127 else 132 else
128 bubble_->Cancel(); 133 bubble_->Cancel();
129 } 134 }
130 135
131 gfx::Size FullscreenExitBubbleViews::FullscreenExitView::GetPreferredSize() { 136 gfx::Size FullscreenExitBubbleViews::FullscreenExitView::GetPreferredSize() {
132 gfx::Size message_size(message_label_.GetPreferredSize()); 137 gfx::Size message_size(message_label_.GetPreferredSize());
133 138
134 gfx::Size button_instruction_area; 139 gfx::Size button_instruction_area;
135 if (link_.IsVisible()) { 140 if (mouse_lock_exit_instruction_.IsVisible()) {
141 button_instruction_area = mouse_lock_exit_instruction_.GetPreferredSize();
142 } else if (link_.IsVisible()) {
136 button_instruction_area = link_.GetPreferredSize(); 143 button_instruction_area = link_.GetPreferredSize();
137 } else { 144 } else {
138 gfx::Size accept_size(accept_button_->GetPreferredSize()); 145 gfx::Size accept_size(accept_button_->GetPreferredSize());
139 gfx::Size deny_size(deny_button_->GetPreferredSize()); 146 gfx::Size deny_size(deny_button_->GetPreferredSize());
140 button_instruction_area.set_height(accept_size.height()); 147 button_instruction_area.set_height(accept_size.height());
141 button_instruction_area.set_width( 148 button_instruction_area.set_width(
142 accept_size.width() + kPaddingPx + deny_size.width()); 149 accept_size.width() + kPaddingPx + deny_size.width());
143 } 150 }
144 151
145 gfx::Insets insets(GetInsets()); 152 gfx::Insets insets(GetInsets());
146 gfx::Size result( 153 gfx::Size result(
147 message_size.width() + kMiddlePaddingPx + button_instruction_area.width(), 154 message_size.width() + kMiddlePaddingPx + button_instruction_area.width(),
148 std::max(message_size.height(), button_instruction_area.height())); 155 std::max(message_size.height(), button_instruction_area.height()));
149 result.Enlarge(insets.width() + 2 * kPaddingPx, 156 result.Enlarge(insets.width() + 2 * kPaddingPx,
150 insets.height() + 2 * kPaddingPx); 157 insets.height() + 2 * kPaddingPx);
151 return result; 158 return result;
152 } 159 }
153 160
154 void FullscreenExitBubbleViews::FullscreenExitView::UpdateContent( 161 void FullscreenExitBubbleViews::FullscreenExitView::UpdateContent(
155 const GURL& url, 162 const GURL& url,
156 FullscreenExitBubbleType bubble_type) { 163 FullscreenExitBubbleType bubble_type) {
157 DCHECK_NE(FEB_TYPE_NONE, bubble_type); 164 DCHECK_NE(FEB_TYPE_NONE, bubble_type);
158 165
159 message_label_.SetText(bubble_->GetCurrentMessageText()); 166 message_label_.SetText(bubble_->GetCurrentMessageText());
160 if (fullscreen_bubble::ShowButtonsForType(bubble_type)) { 167 if (fullscreen_bubble::ShowButtonsForType(bubble_type)) {
161 link_.SetVisible(false); 168 link_.SetVisible(false);
169 mouse_lock_exit_instruction_.SetVisible(false);
162 accept_button_->SetVisible(true); 170 accept_button_->SetVisible(true);
163 deny_button_->SetText(bubble_->GetCurrentDenyButtonText()); 171 deny_button_->SetText(bubble_->GetCurrentDenyButtonText());
164 deny_button_->SetVisible(true); 172 deny_button_->SetVisible(true);
165 deny_button_->ClearMaxTextSize(); 173 deny_button_->ClearMaxTextSize();
166 } else { 174 } else {
167 if (bubble_type == FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION) 175 bool link_visible = true;
168 link_.SetText(browser_fullscreen_exit_text_); 176 string16 accelerator;
169 else 177 if (bubble_type == FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION) {
170 link_.SetText(bubble_->GetInstructionText()); 178 accelerator = browser_fullscreen_exit_accelerator_;
171 link_.SetVisible(true); 179 } else if (bubble_type == FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION) {
180 accelerator = l10n_util::GetStringUTF16(IDS_APP_ESC_KEY);
181 } else {
182 link_visible = false;
183 }
184 #if !defined(OS_CHROMEOS)
185 if (link_visible) {
186 link_.SetText(
187 l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE) +
188 UTF8ToUTF16(" ") +
189 l10n_util::GetStringFUTF16(IDS_EXIT_FULLSCREEN_MODE_ACCELERATOR,
190 accelerator));
191 }
192 #else
193 // Don't need to show the accelerator on ChromeOS, since it has a dedicated
194 // toggle fullscreen button.
195 link_.SetText(l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE));
yzshen1 2011/11/15 21:11:29 You only need to set it when link_visible is true.
jeremya 2011/11/15 22:49:43 Done, I moved the OS_CHROMEOS part to the initiali
196 #endif
197 link_.SetVisible(link_visible);
198 mouse_lock_exit_instruction_.SetVisible(!link_visible);
172 accept_button_->SetVisible(false); 199 accept_button_->SetVisible(false);
173 deny_button_->SetVisible(false); 200 deny_button_->SetVisible(false);
174 } 201 }
175 } 202 }
176 203
177 void FullscreenExitBubbleViews::FullscreenExitView::Layout() { 204 void FullscreenExitBubbleViews::FullscreenExitView::Layout() {
178 // TODO(thakis): Use a LayoutManager instead of doing manual layout. 205 // TODO(thakis): Use a LayoutManager instead of doing manual layout.
179 gfx::Size message_size(message_label_.GetPreferredSize()); 206 gfx::Size message_size(message_label_.GetPreferredSize());
180 gfx::Insets insets(GetInsets()); 207 gfx::Insets insets(GetInsets());
181 int x = insets.left() + kPaddingPx; 208 int x = insets.left() + kPaddingPx;
182 int inner_height = height() - insets.height(); 209 int inner_height = height() - insets.height();
183 210
184 message_label_.SetBounds( 211 message_label_.SetBounds(
185 x, insets.top() + (inner_height - message_size.height()) / 2, 212 x, insets.top() + (inner_height - message_size.height()) / 2,
186 message_size.width(), message_size.height()); 213 message_size.width(), message_size.height());
187 x += message_size.width() + kMiddlePaddingPx; 214 x += message_size.width() + kMiddlePaddingPx;
188 215
189 if (link_.IsVisible()) { 216 if (mouse_lock_exit_instruction_.IsVisible()) {
217 gfx::Size instruction_size(mouse_lock_exit_instruction_.GetPreferredSize());
218 mouse_lock_exit_instruction_.SetBounds(
219 x, insets.top() + (inner_height - instruction_size.height()) / 2,
220 instruction_size.width(), instruction_size.height());
221 } else if (link_.IsVisible()) {
190 gfx::Size link_size(link_.GetPreferredSize()); 222 gfx::Size link_size(link_.GetPreferredSize());
191 link_.SetBounds(x, insets.top() + (inner_height - link_size.height()) / 2, 223 link_.SetBounds(x, insets.top() + (inner_height - link_size.height()) / 2,
192 link_size.width(), link_size.height()); 224 link_size.width(), link_size.height());
193 } else { 225 } else {
194 gfx::Size accept_size(accept_button_->GetPreferredSize()); 226 gfx::Size accept_size(accept_button_->GetPreferredSize());
195 gfx::Size deny_size(deny_button_->GetPreferredSize()); 227 gfx::Size deny_size(deny_button_->GetPreferredSize());
196 int button_y = insets.top() + (inner_height - accept_size.height()) / 2; 228 int button_y = insets.top() + (inner_height - accept_size.height()) / 2;
197 accept_button_->SetBounds( 229 accept_button_->SetBounds(
198 x, button_y, accept_size.width(), accept_size.height()); 230 x, button_y, accept_size.width(), accept_size.height());
199 x += accept_size.width() + kPaddingPx; 231 x += accept_size.width() + kPaddingPx;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 size.set_height(size.height() - popup_bottom + y_offset); 379 size.set_height(size.height() - popup_bottom + y_offset);
348 origin.set_y(origin.y() - y_offset); 380 origin.set_y(origin.y() - y_offset);
349 } 381 }
350 return gfx::Rect(origin, size); 382 return gfx::Rect(origin, size);
351 } 383 }
352 384
353 void FullscreenExitBubbleViews::StartWatchingMouseIfNecessary() { 385 void FullscreenExitBubbleViews::StartWatchingMouseIfNecessary() {
354 if (!fullscreen_bubble::ShowButtonsForType(bubble_type_)) 386 if (!fullscreen_bubble::ShowButtonsForType(bubble_type_))
355 StartWatchingMouse(); 387 StartWatchingMouse();
356 } 388 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698