OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/location_bar_view.h" | 5 #include "chrome/browser/views/location_bar_view.h" |
6 | 6 |
7 #if defined(OS_LINUX) | 7 #if defined(OS_LINUX) |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // Padding on the right and left of the entry field. | 50 // Padding on the right and left of the entry field. |
51 static const int kEntryPadding = 3; | 51 static const int kEntryPadding = 3; |
52 | 52 |
53 // Padding between the entry and the leading/trailing views. | 53 // Padding between the entry and the leading/trailing views. |
54 static const int kInnerPadding = 3; | 54 static const int kInnerPadding = 3; |
55 | 55 |
56 static const SkBitmap* kBackground = NULL; | 56 static const SkBitmap* kBackground = NULL; |
57 | 57 |
58 static const SkBitmap* kPopupBackground = NULL; | 58 static const SkBitmap* kPopupBackground = NULL; |
59 | 59 |
60 // The delay the mouse has to be hovering over the lock/warning icon before the | |
61 // info bubble is shown. | |
62 static const int kInfoBubbleHoverDelayMs = 500; | |
63 | |
64 // The tab key image. | 60 // The tab key image. |
65 static const SkBitmap* kTabButtonBitmap = NULL; | 61 static const SkBitmap* kTabButtonBitmap = NULL; |
66 | 62 |
67 // Returns the short name for a keyword. | 63 // Returns the short name for a keyword. |
68 static std::wstring GetKeywordName(Profile* profile, | 64 static std::wstring GetKeywordName(Profile* profile, |
69 const std::wstring& keyword) { | 65 const std::wstring& keyword) { |
70 // Make sure the TemplateURL still exists. | 66 // Make sure the TemplateURL still exists. |
71 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLModel | 67 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLModel |
72 // to track changes to the model, this should become a DCHECK. | 68 // to track changes to the model, this should become a DCHECK. |
73 const TemplateURL* template_url = | 69 const TemplateURL* template_url = |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 CommandUpdater* command_updater, | 128 CommandUpdater* command_updater, |
133 ToolbarModel* model, | 129 ToolbarModel* model, |
134 Delegate* delegate, | 130 Delegate* delegate, |
135 bool popup_window_mode, | 131 bool popup_window_mode, |
136 const BubblePositioner* bubble_positioner) | 132 const BubblePositioner* bubble_positioner) |
137 : profile_(profile), | 133 : profile_(profile), |
138 command_updater_(command_updater), | 134 command_updater_(command_updater), |
139 model_(model), | 135 model_(model), |
140 delegate_(delegate), | 136 delegate_(delegate), |
141 disposition_(CURRENT_TAB), | 137 disposition_(CURRENT_TAB), |
| 138 security_image_view_(this), |
142 location_entry_view_(NULL), | 139 location_entry_view_(NULL), |
143 selected_keyword_view_(profile), | 140 selected_keyword_view_(profile), |
144 keyword_hint_view_(profile), | 141 keyword_hint_view_(profile), |
145 type_to_search_view_(l10n_util::GetString(IDS_OMNIBOX_EMPTY_TEXT)), | 142 type_to_search_view_(l10n_util::GetString(IDS_OMNIBOX_EMPTY_TEXT)), |
146 security_image_view_(this, profile, model, bubble_positioner), | |
147 popup_window_mode_(popup_window_mode), | 143 popup_window_mode_(popup_window_mode), |
148 first_run_bubble_(this), | 144 first_run_bubble_(this), |
149 bubble_positioner_(bubble_positioner) { | 145 bubble_positioner_(bubble_positioner) { |
150 DCHECK(profile_); | 146 DCHECK(profile_); |
151 SetID(VIEW_ID_LOCATION_BAR); | 147 SetID(VIEW_ID_LOCATION_BAR); |
152 SetFocusable(true); | 148 SetFocusable(true); |
153 | 149 |
154 if (!kBackground) { | 150 if (!kBackground) { |
155 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); | 151 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); |
156 kBackground = rb.GetBitmapNamed(IDR_LOCATIONBG); | 152 kBackground = rb.GetBitmapNamed(IDR_LOCATIONBG); |
157 kPopupBackground = rb.GetBitmapNamed(IDR_LOCATIONBG_POPUPMODE_CENTER); | 153 kPopupBackground = rb.GetBitmapNamed(IDR_LOCATIONBG_POPUPMODE_CENTER); |
158 } | 154 } |
159 } | 155 } |
160 | 156 |
161 LocationBarView::~LocationBarView() { | 157 LocationBarView::~LocationBarView() { |
162 } | 158 } |
163 | 159 |
164 void LocationBarView::Init() { | 160 void LocationBarView::Init() { |
165 if (popup_window_mode_) { | 161 if (popup_window_mode_) { |
166 font_ = ResourceBundle::GetSharedInstance().GetFont( | 162 font_ = ResourceBundle::GetSharedInstance().GetFont( |
167 ResourceBundle::BaseFont); | 163 ResourceBundle::BaseFont); |
168 } else { | 164 } else { |
169 // Use a larger version of the system font. | 165 // Use a larger version of the system font. |
170 font_ = font_.DeriveFont(3); | 166 font_ = font_.DeriveFont(3); |
171 } | 167 } |
172 | 168 |
| 169 AddChildView(&security_image_view_); |
| 170 security_image_view_.SetVisible(false); |
| 171 security_image_view_.set_parent_owned(false); |
| 172 |
173 // URL edit field. | 173 // URL edit field. |
174 // View container for URL edit field. | 174 // View container for URL edit field. |
175 #if defined(OS_WIN) | 175 #if defined(OS_WIN) |
176 views::Widget* widget = GetWidget(); | |
177 location_entry_.reset(new AutocompleteEditViewWin(font_, this, model_, this, | 176 location_entry_.reset(new AutocompleteEditViewWin(font_, this, model_, this, |
178 widget->GetNativeView(), | 177 GetWidget()->GetNativeView(), profile_, command_updater_, |
179 profile_, command_updater_, | 178 popup_window_mode_, bubble_positioner_)); |
180 popup_window_mode_, | |
181 bubble_positioner_)); | |
182 #else | 179 #else |
183 location_entry_.reset(new AutocompleteEditViewGtk(this, model_, profile_, | 180 location_entry_.reset(new AutocompleteEditViewGtk(this, model_, profile_, |
184 command_updater_, | 181 command_updater_, popup_window_mode_, bubble_positioner_)); |
185 popup_window_mode_, | |
186 bubble_positioner_)); | |
187 location_entry_->Init(); | 182 location_entry_->Init(); |
188 // Make all the children of the widget visible. NOTE: this won't display | 183 // Make all the children of the widget visible. NOTE: this won't display |
189 // anything, it just toggles the visible flag. | 184 // anything, it just toggles the visible flag. |
190 gtk_widget_show_all(location_entry_->widget()); | 185 gtk_widget_show_all(location_entry_->GetNativeView()); |
191 // Hide the widget. NativeViewHostGtk will make it visible again as | 186 // Hide the widget. NativeViewHostGtk will make it visible again as |
192 // necessary. | 187 // necessary. |
193 gtk_widget_hide(location_entry_->widget()); | 188 gtk_widget_hide(location_entry_->GetNativeView()); |
194 #endif | 189 #endif |
195 location_entry_view_ = new views::NativeViewHost; | 190 location_entry_view_ = new views::NativeViewHost; |
196 location_entry_view_->SetID(VIEW_ID_AUTOCOMPLETE); | 191 location_entry_view_->SetID(VIEW_ID_AUTOCOMPLETE); |
197 AddChildView(location_entry_view_); | 192 AddChildView(location_entry_view_); |
198 location_entry_view_->set_focus_view(this); | 193 location_entry_view_->set_focus_view(this); |
199 location_entry_view_->Attach( | 194 location_entry_view_->Attach(location_entry_->GetNativeView()); |
200 #if defined(OS_WIN) | |
201 location_entry_->m_hWnd | |
202 #else | |
203 location_entry_->widget() | |
204 #endif | |
205 ); // NOLINT | |
206 | 195 |
207 AddChildView(&selected_keyword_view_); | 196 AddChildView(&selected_keyword_view_); |
208 selected_keyword_view_.SetFont(font_); | 197 selected_keyword_view_.SetFont(font_); |
209 selected_keyword_view_.SetVisible(false); | 198 selected_keyword_view_.SetVisible(false); |
210 selected_keyword_view_.set_parent_owned(false); | 199 selected_keyword_view_.set_parent_owned(false); |
211 | 200 |
212 SkColor dimmed_text = GetColor(false, DEEMPHASIZED_TEXT); | 201 SkColor dimmed_text = GetColor(ToolbarModel::NONE, DEEMPHASIZED_TEXT); |
213 | 202 |
214 AddChildView(&type_to_search_view_); | 203 AddChildView(&type_to_search_view_); |
215 type_to_search_view_.SetVisible(false); | 204 type_to_search_view_.SetVisible(false); |
216 type_to_search_view_.SetFont(font_); | 205 type_to_search_view_.SetFont(font_); |
217 type_to_search_view_.SetColor(dimmed_text); | 206 type_to_search_view_.SetColor(dimmed_text); |
218 type_to_search_view_.set_parent_owned(false); | 207 type_to_search_view_.set_parent_owned(false); |
219 | 208 |
220 AddChildView(&keyword_hint_view_); | 209 AddChildView(&keyword_hint_view_); |
221 keyword_hint_view_.SetVisible(false); | 210 keyword_hint_view_.SetVisible(false); |
222 keyword_hint_view_.SetFont(font_); | 211 keyword_hint_view_.SetFont(font_); |
223 keyword_hint_view_.SetColor(dimmed_text); | 212 keyword_hint_view_.SetColor(dimmed_text); |
224 keyword_hint_view_.set_parent_owned(false); | 213 keyword_hint_view_.set_parent_owned(false); |
225 | 214 |
226 AddChildView(&security_image_view_); | 215 AddChildView(&security_info_label_); |
227 security_image_view_.SetVisible(false); | 216 security_info_label_.SetVisible(false); |
228 security_image_view_.set_parent_owned(false); | 217 security_info_label_.set_parent_owned(false); |
229 | 218 |
230 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 219 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
231 ContentSettingImageView* content_blocked_view = | 220 ContentSettingImageView* content_blocked_view = |
232 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this, | 221 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this, |
233 profile_, bubble_positioner_); | 222 profile_, bubble_positioner_); |
234 content_setting_views_.push_back(content_blocked_view); | 223 content_setting_views_.push_back(content_blocked_view); |
235 AddChildView(content_blocked_view); | 224 AddChildView(content_blocked_view); |
236 content_blocked_view->SetVisible(false); | 225 content_blocked_view->SetVisible(false); |
237 } | 226 } |
238 | 227 |
239 AddChildView(&info_label_); | |
240 info_label_.SetVisible(false); | |
241 info_label_.set_parent_owned(false); | |
242 | |
243 // Notify us when any ancestor is resized. In this case we want to tell the | 228 // Notify us when any ancestor is resized. In this case we want to tell the |
244 // AutocompleteEditView to close its popup. | 229 // AutocompleteEditView to close its popup. |
245 SetNotifyWhenVisibleBoundsInRootChanges(true); | 230 SetNotifyWhenVisibleBoundsInRootChanges(true); |
246 | 231 |
247 // Initialize the location entry. We do this to avoid a black flash which is | 232 // Initialize the location entry. We do this to avoid a black flash which is |
248 // visible when the location entry has just been initialized. | 233 // visible when the location entry has just been initialized. |
249 Update(NULL); | 234 Update(NULL); |
250 | 235 |
251 OnChanged(); | 236 OnChanged(); |
252 } | 237 } |
253 | 238 |
254 bool LocationBarView::IsInitialized() const { | 239 bool LocationBarView::IsInitialized() const { |
255 return location_entry_view_ != NULL; | 240 return location_entry_view_ != NULL; |
256 } | 241 } |
257 | 242 |
258 // static | 243 // static |
259 SkColor LocationBarView::GetColor(bool is_secure, ColorKind kind) { | 244 SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level, |
260 enum SecurityState { | 245 ColorKind kind) { |
261 NOT_SECURE = 0, | 246 switch (kind) { |
262 SECURE, | |
263 NUM_STATES | |
264 }; | |
265 | |
266 static bool initialized = false; | |
267 static SkColor colors[NUM_STATES][NUM_KINDS]; | |
268 if (!initialized) { | |
269 #if defined(OS_WIN) | 247 #if defined(OS_WIN) |
270 colors[NOT_SECURE][BACKGROUND] = color_utils::GetSysSkColor(COLOR_WINDOW); | 248 case BACKGROUND: return color_utils::GetSysSkColor(COLOR_WINDOW); |
271 colors[NOT_SECURE][TEXT] = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); | 249 case TEXT: return color_utils::GetSysSkColor(COLOR_WINDOWTEXT); |
272 colors[NOT_SECURE][SELECTED_TEXT] = | 250 case SELECTED_TEXT: return color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT); |
273 color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT); | |
274 #else | 251 #else |
275 // TODO(beng): source from theme provider. | 252 // TODO(beng): source from theme provider. |
276 colors[NOT_SECURE][BACKGROUND] = SK_ColorWHITE; | 253 case BACKGROUND: return SK_ColorWHITE; |
277 colors[NOT_SECURE][TEXT] = SK_ColorBLACK; | 254 case TEXT: return SK_ColorBLACK; |
278 colors[NOT_SECURE][SELECTED_TEXT] = SK_ColorWHITE; | 255 case SELECTED_TEXT: return SK_ColorWHITE; |
279 #endif | 256 #endif |
280 colors[SECURE][BACKGROUND] = SkColorSetRGB(255, 245, 195); | 257 |
281 colors[SECURE][TEXT] = SK_ColorBLACK; | 258 case DEEMPHASIZED_TEXT: |
282 colors[SECURE][SELECTED_TEXT] = 0; // Unused | 259 return color_utils::AlphaBlend(GetColor(security_level, TEXT), |
283 colors[NOT_SECURE][DEEMPHASIZED_TEXT] = | 260 GetColor(security_level, BACKGROUND), 128); |
284 color_utils::AlphaBlend(colors[NOT_SECURE][TEXT], | 261 |
285 colors[NOT_SECURE][BACKGROUND], 128); | 262 case SECURITY_TEXT: { |
286 colors[SECURE][DEEMPHASIZED_TEXT] = | 263 SkColor color; |
287 color_utils::AlphaBlend(colors[SECURE][TEXT], | 264 switch (security_level) { |
288 colors[SECURE][BACKGROUND], 128); | 265 case ToolbarModel::EV_SECURE: |
289 colors[NOT_SECURE][SECURITY_TEXT] = color_utils::GetReadableColor( | 266 color = SkColorSetRGB(7, 149, 0); |
290 SkColorSetRGB(200, 0, 0), colors[NOT_SECURE][BACKGROUND]); | 267 break; |
291 colors[SECURE][SECURITY_TEXT] = SkColorSetRGB(0, 150, 20); | 268 |
292 colors[NOT_SECURE][SECURITY_INFO_BUBBLE_TEXT] = | 269 case ToolbarModel::SECURE: |
293 colors[NOT_SECURE][SECURITY_TEXT]; | 270 case ToolbarModel::SECURITY_WARNING: |
294 colors[SECURE][SECURITY_INFO_BUBBLE_TEXT] = color_utils::GetReadableColor( | 271 color = SkColorSetRGB(0, 14, 149); |
295 SkColorSetRGB(0, 153, 51), colors[NOT_SECURE][BACKGROUND]); | 272 break; |
296 colors[NOT_SECURE][SCHEME_STRIKEOUT] = color_utils::GetReadableColor( | 273 |
297 SkColorSetRGB(210, 0, 0), colors[NOT_SECURE][BACKGROUND]); | 274 case ToolbarModel::SECURITY_ERROR: |
298 colors[SECURE][SCHEME_STRIKEOUT] = 0; // Unused | 275 color = SkColorSetRGB(162, 0, 0); |
299 initialized = true; | 276 break; |
| 277 |
| 278 default: |
| 279 NOTREACHED(); |
| 280 return GetColor(security_level, TEXT); |
| 281 } |
| 282 return color_utils::GetReadableColor(color, GetColor(security_level, |
| 283 BACKGROUND)); |
| 284 } |
| 285 |
| 286 default: |
| 287 NOTREACHED(); |
| 288 return GetColor(security_level, TEXT); |
300 } | 289 } |
301 | |
302 return colors[is_secure ? SECURE : NOT_SECURE][kind]; | |
303 } | 290 } |
304 | 291 |
305 void LocationBarView::Update(const TabContents* tab_for_state_restoring) { | 292 void LocationBarView::Update(const TabContents* tab_for_state_restoring) { |
306 SetSecurityIcon(model_->GetIcon()); | 293 security_image_view_.SetSecurityIcon(model_->GetSecurityIcon()); |
| 294 // The visibility of the |security_info_label_| will be set during layout. |
| 295 std::wstring security_info_text(model_->GetSecurityInfoText()); |
| 296 security_info_label_.SetText(security_info_text); |
| 297 if (!security_info_text.empty()) { |
| 298 security_info_label_.SetColor(GetColor(model_->GetSecurityLevel(), |
| 299 SECURITY_TEXT)); |
| 300 } |
| 301 |
307 RefreshContentSettingViews(); | 302 RefreshContentSettingViews(); |
308 RefreshPageActionViews(); | 303 RefreshPageActionViews(); |
309 std::wstring info_text, info_tooltip; | |
310 ToolbarModel::InfoTextType info_text_type = | |
311 model_->GetInfoText(&info_text, &info_tooltip); | |
312 SetInfoText(info_text, info_text_type, info_tooltip); | |
313 location_entry_->Update(tab_for_state_restoring); | 304 location_entry_->Update(tab_for_state_restoring); |
314 Layout(); | 305 Layout(); |
315 SchedulePaint(); | 306 SchedulePaint(); |
316 } | 307 } |
317 | 308 |
318 void LocationBarView::UpdateContentSettingsIcons() { | 309 void LocationBarView::UpdateContentSettingsIcons() { |
319 RefreshContentSettingViews(); | 310 RefreshContentSettingViews(); |
320 | 311 |
321 Layout(); | 312 Layout(); |
322 SchedulePaint(); | 313 SchedulePaint(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 void LocationBarView::SetProfile(Profile* profile) { | 346 void LocationBarView::SetProfile(Profile* profile) { |
356 DCHECK(profile); | 347 DCHECK(profile); |
357 if (profile_ != profile) { | 348 if (profile_ != profile) { |
358 profile_ = profile; | 349 profile_ = profile; |
359 location_entry_->model()->SetProfile(profile); | 350 location_entry_->model()->SetProfile(profile); |
360 selected_keyword_view_.set_profile(profile); | 351 selected_keyword_view_.set_profile(profile); |
361 keyword_hint_view_.set_profile(profile); | 352 keyword_hint_view_.set_profile(profile); |
362 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 353 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
363 i != content_setting_views_.end(); ++i) | 354 i != content_setting_views_.end(); ++i) |
364 (*i)->set_profile(profile); | 355 (*i)->set_profile(profile); |
365 security_image_view_.set_profile(profile); | |
366 } | 356 } |
367 } | 357 } |
368 | 358 |
369 TabContents* LocationBarView::GetTabContents() const { | 359 TabContents* LocationBarView::GetTabContents() const { |
370 return delegate_->GetTabContents(); | 360 return delegate_->GetTabContents(); |
371 } | 361 } |
372 | 362 |
373 void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction *page_action, | 363 void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction *page_action, |
374 bool preview_enabled) { | 364 bool preview_enabled) { |
375 DCHECK(page_action); | 365 DCHECK(page_action); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 void LocationBarView::Paint(gfx::Canvas* canvas) { | 402 void LocationBarView::Paint(gfx::Canvas* canvas) { |
413 View::Paint(canvas); | 403 View::Paint(canvas); |
414 | 404 |
415 const SkBitmap* background = | 405 const SkBitmap* background = |
416 popup_window_mode_ ? | 406 popup_window_mode_ ? |
417 kPopupBackground : | 407 kPopupBackground : |
418 GetThemeProvider()->GetBitmapNamed(IDR_LOCATIONBG); | 408 GetThemeProvider()->GetBitmapNamed(IDR_LOCATIONBG); |
419 | 409 |
420 canvas->TileImageInt(*background, 0, 0, 0, 0, width(), height()); | 410 canvas->TileImageInt(*background, 0, 0, 0, 0, width(), height()); |
421 int top_margin = TopMargin(); | 411 int top_margin = TopMargin(); |
422 canvas->FillRectInt( | 412 canvas->FillRectInt(GetColor(ToolbarModel::NONE, BACKGROUND), 0, |
423 GetColor(model_->GetSchemeSecurityLevel() == ToolbarModel::SECURE, | 413 top_margin, width(), |
424 BACKGROUND), | 414 std::max(height() - top_margin - kVertMargin, 0)); |
425 0, top_margin, width(), std::max(height() - top_margin - kVertMargin, 0)); | |
426 } | 415 } |
427 | 416 |
428 void LocationBarView::VisibleBoundsInRootChanged() { | 417 void LocationBarView::VisibleBoundsInRootChanged() { |
429 location_entry_->ClosePopup(); | 418 location_entry_->ClosePopup(); |
430 } | 419 } |
431 | 420 |
432 #if defined(OS_WIN) | 421 #if defined(OS_WIN) |
433 bool LocationBarView::OnMousePressed(const views::MouseEvent& event) { | 422 bool LocationBarView::OnMousePressed(const views::MouseEvent& event) { |
434 UINT msg; | 423 UINT msg; |
435 if (event.IsLeftMouseButton()) { | 424 if (event.IsLeftMouseButton()) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 DCHECK(delegate_->GetTabContents()); | 528 DCHECK(delegate_->GetTabContents()); |
540 return UTF16ToWideHack(delegate_->GetTabContents()->GetTitle()); | 529 return UTF16ToWideHack(delegate_->GetTabContents()->GetTitle()); |
541 } | 530 } |
542 | 531 |
543 void LocationBarView::DoLayout(const bool force_layout) { | 532 void LocationBarView::DoLayout(const bool force_layout) { |
544 if (!location_entry_.get()) | 533 if (!location_entry_.get()) |
545 return; | 534 return; |
546 | 535 |
547 int entry_width = width() - (kEntryPadding * 2); | 536 int entry_width = width() - (kEntryPadding * 2); |
548 | 537 |
| 538 gfx::Size security_image_size; |
| 539 if (security_image_view_.IsVisible()) { |
| 540 security_image_size = security_image_view_.GetPreferredSize(); |
| 541 entry_width -= security_image_size.width() + kInnerPadding; |
| 542 } |
549 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 543 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
550 i != page_action_views_.end(); ++i) { | 544 i != page_action_views_.end(); ++i) { |
551 if ((*i)->IsVisible()) | 545 if ((*i)->IsVisible()) |
552 entry_width -= (*i)->GetPreferredSize().width() + kInnerPadding; | 546 entry_width -= (*i)->GetPreferredSize().width() + kInnerPadding; |
553 } | 547 } |
554 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 548 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
555 i != content_setting_views_.end(); ++i) { | 549 i != content_setting_views_.end(); ++i) { |
556 if ((*i)->IsVisible()) | 550 if ((*i)->IsVisible()) |
557 entry_width -= (*i)->GetPreferredSize().width() + kInnerPadding; | 551 entry_width -= (*i)->GetPreferredSize().width() + kInnerPadding; |
558 } | 552 } |
559 gfx::Size security_image_size; | |
560 if (security_image_view_.IsVisible()) { | |
561 security_image_size = security_image_view_.GetPreferredSize(); | |
562 entry_width -= security_image_size.width() + kInnerPadding; | |
563 } | |
564 gfx::Size info_label_size; | |
565 if (info_label_.IsVisible()) { | |
566 info_label_size = info_label_.GetPreferredSize(); | |
567 entry_width -= (info_label_size.width() + kInnerPadding); | |
568 } | |
569 | 553 |
570 #if defined(OS_WIN) | 554 #if defined(OS_WIN) |
571 RECT formatting_rect; | 555 RECT formatting_rect; |
572 location_entry_->GetRect(&formatting_rect); | 556 location_entry_->GetRect(&formatting_rect); |
573 RECT edit_bounds; | 557 RECT edit_bounds; |
574 location_entry_->GetClientRect(&edit_bounds); | 558 location_entry_->GetClientRect(&edit_bounds); |
575 int max_edit_width = entry_width - formatting_rect.left - | 559 int max_edit_width = entry_width - formatting_rect.left - |
576 (edit_bounds.right - formatting_rect.right); | 560 (edit_bounds.right - formatting_rect.right); |
577 #else | 561 #else |
578 int max_edit_width = entry_width; | 562 int max_edit_width = entry_width; |
579 #endif | 563 #endif |
580 | 564 |
581 if (max_edit_width < 0) | 565 if (max_edit_width < 0) |
582 return; | 566 return; |
583 const int available_width = AvailableWidth(max_edit_width); | 567 const int available_width = AvailableWidth(max_edit_width); |
584 bool needs_layout = force_layout; | 568 bool needs_layout = force_layout; |
585 needs_layout |= AdjustHints(available_width); | 569 needs_layout |= AdjustAutocollapseViews(available_width); |
586 | 570 |
587 if (!needs_layout) | 571 if (!needs_layout) |
588 return; | 572 return; |
589 | 573 |
590 // TODO(sky): baseline layout. | 574 // TODO(sky): baseline layout. |
591 int location_y = TopMargin(); | 575 int location_y = TopMargin(); |
592 int location_height = std::max(height() - location_y - kVertMargin, 0); | 576 int location_height = std::max(height() - location_y - kVertMargin, 0); |
593 | 577 |
594 // First set the bounds for the label that appears to the right of the | 578 // Lay out items to the right of the edit field. |
595 // security icon. | |
596 int offset = width() - kEntryPadding; | 579 int offset = width() - kEntryPadding; |
597 if (info_label_.IsVisible()) { | |
598 offset -= info_label_size.width(); | |
599 info_label_.SetBounds(offset, location_y, | |
600 info_label_size.width(), location_height); | |
601 offset -= kInnerPadding; | |
602 } | |
603 if (security_image_view_.IsVisible()) { | |
604 offset -= security_image_size.width(); | |
605 security_image_view_.SetBounds(offset, location_y, | |
606 security_image_size.width(), | |
607 location_height); | |
608 offset -= kInnerPadding; | |
609 } | |
610 | |
611 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 580 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
612 i != page_action_views_.end(); ++i) { | 581 i != page_action_views_.end(); ++i) { |
613 if ((*i)->IsVisible()) { | 582 if ((*i)->IsVisible()) { |
614 int page_action_width = (*i)->GetPreferredSize().width(); | 583 int page_action_width = (*i)->GetPreferredSize().width(); |
615 offset -= page_action_width; | 584 offset -= page_action_width; |
616 (*i)->SetBounds(offset, location_y, page_action_width, location_height); | 585 (*i)->SetBounds(offset, location_y, page_action_width, location_height); |
617 offset -= kInnerPadding; | 586 offset -= kInnerPadding; |
618 } | 587 } |
619 } | 588 } |
620 // We use a reverse_iterator here because we're laying out the views from | 589 // We use a reverse_iterator here because we're laying out the views from |
621 // right to left but in the vector they're ordered left to right. | 590 // right to left but in the vector they're ordered left to right. |
622 for (ContentSettingViews::const_reverse_iterator | 591 for (ContentSettingViews::const_reverse_iterator |
623 i(content_setting_views_.rbegin()); i != content_setting_views_.rend(); | 592 i(content_setting_views_.rbegin()); i != content_setting_views_.rend(); |
624 ++i) { | 593 ++i) { |
625 if ((*i)->IsVisible()) { | 594 if ((*i)->IsVisible()) { |
626 int content_blocked_width = (*i)->GetPreferredSize().width(); | 595 int content_blocked_width = (*i)->GetPreferredSize().width(); |
627 offset -= content_blocked_width; | 596 offset -= content_blocked_width; |
628 (*i)->SetBounds(offset, location_y, content_blocked_width, | 597 (*i)->SetBounds(offset, location_y, content_blocked_width, |
629 location_height); | 598 location_height); |
630 offset -= kInnerPadding; | 599 offset -= kInnerPadding; |
631 } | 600 } |
632 } | 601 } |
633 gfx::Rect location_bounds(kEntryPadding, location_y, entry_width, | 602 |
634 location_height); | 603 // Now lay out items to the left of the edit field. |
| 604 offset = kEntryPadding; |
| 605 if (security_image_view_.IsVisible()) { |
| 606 security_image_view_.SetBounds(offset, location_y, |
| 607 security_image_size.width(), |
| 608 location_height); |
| 609 offset = security_image_view_.bounds().right() + kInnerPadding; |
| 610 } |
| 611 |
| 612 // Now lay out the edit field and views that autocollapse to give it more |
| 613 // room. |
| 614 gfx::Rect location_bounds(offset, location_y, entry_width, location_height); |
635 if (selected_keyword_view_.IsVisible()) { | 615 if (selected_keyword_view_.IsVisible()) { |
636 LayoutView(true, &selected_keyword_view_, available_width, | 616 LayoutView(true, &selected_keyword_view_, available_width, |
637 &location_bounds); | 617 &location_bounds); |
638 } else if (keyword_hint_view_.IsVisible()) { | 618 } else if (keyword_hint_view_.IsVisible()) { |
639 LayoutView(false, &keyword_hint_view_, available_width, | 619 LayoutView(false, &keyword_hint_view_, available_width, |
640 &location_bounds); | 620 &location_bounds); |
641 } else if (type_to_search_view_.IsVisible()) { | 621 } else if (type_to_search_view_.IsVisible()) { |
642 LayoutView(false, &type_to_search_view_, available_width, | 622 LayoutView(false, &type_to_search_view_, available_width, |
643 &location_bounds); | 623 &location_bounds); |
644 } | 624 } |
| 625 if (security_info_label_.IsVisible()) { |
| 626 LayoutView(false, &security_info_label_, available_width, |
| 627 &location_bounds); |
| 628 } |
645 | 629 |
646 location_entry_view_->SetBounds(location_bounds); | 630 location_entry_view_->SetBounds(location_bounds); |
647 if (!force_layout) { | 631 if (!force_layout) { |
648 // If force_layout is false and we got this far it means one of the views | 632 // If force_layout is false and we got this far it means one of the views |
649 // was added/removed or changed in size. We need to paint ourselves. | 633 // was added/removed or changed in size. We need to paint ourselves. |
650 SchedulePaint(); | 634 SchedulePaint(); |
651 } | 635 } |
652 } | 636 } |
653 | 637 |
654 int LocationBarView::TopMargin() const { | 638 int LocationBarView::TopMargin() const { |
(...skipping 17 matching lines...) Expand all Loading... |
672 return (pref_width + kInnerPadding <= available_width); | 656 return (pref_width + kInnerPadding <= available_width); |
673 } | 657 } |
674 | 658 |
675 bool LocationBarView::NeedsResize(View* view, int available_width) { | 659 bool LocationBarView::NeedsResize(View* view, int available_width) { |
676 gfx::Size size = view->GetPreferredSize(); | 660 gfx::Size size = view->GetPreferredSize(); |
677 if (!UsePref(size.width(), available_width)) | 661 if (!UsePref(size.width(), available_width)) |
678 size = view->GetMinimumSize(); | 662 size = view->GetMinimumSize(); |
679 return (view->width() != size.width()); | 663 return (view->width() != size.width()); |
680 } | 664 } |
681 | 665 |
682 bool LocationBarView::AdjustHints(int available_width) { | 666 bool LocationBarView::AdjustAutocollapseViews(int available_width) { |
683 const std::wstring keyword(location_entry_->model()->keyword()); | 667 const std::wstring keyword(location_entry_->model()->keyword()); |
684 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint()); | 668 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint()); |
685 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint; | 669 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint; |
686 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint; | 670 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint; |
687 bool show_search_hint(location_entry_->model()->show_search_hint()); | 671 bool show_search_hint(location_entry_->model()->show_search_hint()); |
688 DCHECK(keyword.empty() || !show_search_hint); | 672 DCHECK(keyword.empty() || !show_search_hint); |
689 | 673 |
690 if (show_search_hint) { | 674 if (show_search_hint) { |
691 // Only show type to search if all the text fits. | 675 // Only show type to search if all the text fits. |
692 gfx::Size view_pref = type_to_search_view_.GetPreferredSize(); | 676 gfx::Size preferred_size = type_to_search_view_.GetPreferredSize(); |
693 show_search_hint = UsePref(view_pref.width(), available_width); | 677 show_search_hint = UsePref(preferred_size.width(), available_width); |
| 678 } |
| 679 |
| 680 bool show_security_info_label = !security_info_label_.GetText().empty(); |
| 681 if (show_security_info_label) { |
| 682 // Only show the security info label if all the text fits. |
| 683 gfx::Size preferred_size = security_info_label_.GetPreferredSize(); |
| 684 show_security_info_label = UsePref(preferred_size.width(), available_width); |
694 } | 685 } |
695 | 686 |
696 // NOTE: This isn't just one big || statement as ToggleVisibility MUST be | 687 // NOTE: This isn't just one big || statement as ToggleVisibility MUST be |
697 // invoked for each view. | 688 // invoked for each view. |
698 bool needs_layout = false; | 689 bool needs_layout = false; |
699 needs_layout |= ToggleVisibility(show_selected_keyword, | 690 needs_layout |= ToggleVisibility(show_selected_keyword, |
700 &selected_keyword_view_); | 691 &selected_keyword_view_); |
701 needs_layout |= ToggleVisibility(show_keyword_hint, &keyword_hint_view_); | 692 needs_layout |= ToggleVisibility(show_keyword_hint, &keyword_hint_view_); |
702 needs_layout |= ToggleVisibility(show_search_hint, &type_to_search_view_); | 693 needs_layout |= ToggleVisibility(show_search_hint, &type_to_search_view_); |
| 694 needs_layout |= ToggleVisibility(show_security_info_label, |
| 695 &security_info_label_); |
703 if (show_selected_keyword) { | 696 if (show_selected_keyword) { |
704 if (selected_keyword_view_.keyword() != keyword) { | 697 if (selected_keyword_view_.keyword() != keyword) { |
705 needs_layout = true; | 698 needs_layout = true; |
706 selected_keyword_view_.SetKeyword(keyword); | 699 selected_keyword_view_.SetKeyword(keyword); |
707 } | 700 } |
708 needs_layout |= NeedsResize(&selected_keyword_view_, available_width); | 701 needs_layout |= NeedsResize(&selected_keyword_view_, available_width); |
709 } else if (show_keyword_hint) { | 702 } else if (show_keyword_hint) { |
710 if (keyword_hint_view_.keyword() != keyword) { | 703 if (keyword_hint_view_.keyword() != keyword) { |
711 needs_layout = true; | 704 needs_layout = true; |
712 keyword_hint_view_.SetKeyword(keyword); | 705 keyword_hint_view_.SetKeyword(keyword); |
713 } | 706 } |
714 needs_layout |= NeedsResize(&keyword_hint_view_, available_width); | 707 needs_layout |= NeedsResize(&keyword_hint_view_, available_width); |
715 } | 708 } |
716 | 709 |
717 return needs_layout; | 710 return needs_layout; |
718 } | 711 } |
719 | 712 |
720 void LocationBarView::LayoutView(bool leading, | 713 void LocationBarView::LayoutView(bool leading, |
721 views::View* view, | 714 views::View* view, |
722 int available_width, | 715 int available_width, |
723 gfx::Rect* bounds) { | 716 gfx::Rect* bounds) { |
724 DCHECK(view && bounds); | 717 DCHECK(view && bounds); |
725 gfx::Size view_size = view->GetPreferredSize(); | 718 gfx::Size view_size = view->GetPreferredSize(); |
726 if (!UsePref(view_size.width(), available_width)) | 719 if (!UsePref(view_size.width(), available_width)) |
727 view_size = view->GetMinimumSize(); | 720 view_size = view->GetMinimumSize(); |
728 if (view_size.width() + kInnerPadding < bounds->width()) { | 721 if (view_size.width() + kInnerPadding >= bounds->width()) { |
729 view->SetVisible(true); | 722 view->SetVisible(false); |
730 if (leading) { | 723 return; |
731 view->SetBounds(bounds->x(), bounds->y(), view_size.width(), | 724 } |
732 bounds->height()); | 725 if (leading) { |
733 bounds->Offset(view_size.width() + kInnerPadding, 0); | 726 view->SetBounds(bounds->x(), bounds->y(), view_size.width(), |
734 } else { | 727 bounds->height()); |
735 view->SetBounds(bounds->right() - view_size.width(), bounds->y(), | 728 bounds->Offset(view_size.width() + kInnerPadding, 0); |
736 view_size.width(), bounds->height()); | |
737 } | |
738 bounds->set_width(bounds->width() - view_size.width() - kInnerPadding); | |
739 } else { | 729 } else { |
740 view->SetVisible(false); | 730 view->SetBounds(bounds->right() - view_size.width(), bounds->y(), |
| 731 view_size.width(), bounds->height()); |
741 } | 732 } |
742 } | 733 bounds->set_width(bounds->width() - view_size.width() - kInnerPadding); |
743 | 734 view->SetVisible(true); |
744 void LocationBarView::SetSecurityIcon(ToolbarModel::Icon icon) { | |
745 switch (icon) { | |
746 case ToolbarModel::LOCK_ICON: | |
747 security_image_view_.SetImageShown(SecurityImageView::LOCK); | |
748 security_image_view_.SetVisible(true); | |
749 break; | |
750 case ToolbarModel::WARNING_ICON: | |
751 security_image_view_.SetImageShown(SecurityImageView::WARNING); | |
752 security_image_view_.SetVisible(true); | |
753 break; | |
754 case ToolbarModel::NO_ICON: | |
755 security_image_view_.SetVisible(false); | |
756 break; | |
757 default: | |
758 NOTREACHED(); | |
759 security_image_view_.SetVisible(false); | |
760 break; | |
761 } | |
762 } | 735 } |
763 | 736 |
764 void LocationBarView::RefreshContentSettingViews() { | 737 void LocationBarView::RefreshContentSettingViews() { |
765 const TabContents* tab_contents = delegate_->GetTabContents(); | 738 const TabContents* tab_contents = delegate_->GetTabContents(); |
766 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 739 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
767 i != content_setting_views_.end(); ++i) { | 740 i != content_setting_views_.end(); ++i) { |
768 (*i)->UpdateFromTabContents( | 741 (*i)->UpdateFromTabContents( |
769 model_->input_in_progress() ? NULL : tab_contents); | 742 model_->input_in_progress() ? NULL : tab_contents); |
770 } | 743 } |
771 } | 744 } |
(...skipping 25 matching lines...) Expand all Loading... |
797 | 770 |
798 // On startup we sometimes haven't loaded any extensions. This makes sure | 771 // On startup we sometimes haven't loaded any extensions. This makes sure |
799 // we catch up when the extensions (and any page actions) load. | 772 // we catch up when the extensions (and any page actions) load. |
800 if (page_actions.size() != page_action_views_.size()) { | 773 if (page_actions.size() != page_action_views_.size()) { |
801 DeletePageActionViews(); // Delete the old views (if any). | 774 DeletePageActionViews(); // Delete the old views (if any). |
802 | 775 |
803 page_action_views_.resize(page_actions.size()); | 776 page_action_views_.resize(page_actions.size()); |
804 | 777 |
805 for (size_t i = 0; i < page_actions.size(); ++i) { | 778 for (size_t i = 0; i < page_actions.size(); ++i) { |
806 page_action_views_[i] = new PageActionWithBadgeView( | 779 page_action_views_[i] = new PageActionWithBadgeView( |
807 new PageActionImageView(this, profile_, | 780 new PageActionImageView(this, profile_, page_actions[i])); |
808 page_actions[i], bubble_positioner_)); | |
809 page_action_views_[i]->SetVisible(false); | 781 page_action_views_[i]->SetVisible(false); |
810 AddChildView(page_action_views_[i]); | 782 AddChildView(page_action_views_[i]); |
811 } | 783 } |
812 } | 784 } |
813 | 785 |
814 TabContents* contents = delegate_->GetTabContents(); | 786 TabContents* contents = delegate_->GetTabContents(); |
815 if (!page_action_views_.empty() && contents) { | 787 if (!page_action_views_.empty() && contents) { |
816 GURL url = GURL(WideToUTF8(model_->GetText())); | 788 GURL url = GURL(WideToUTF8(model_->GetText())); |
817 | 789 |
818 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 790 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
819 i != page_action_views_.end(); ++i) { | 791 i != page_action_views_.end(); ++i) { |
820 (*i)->UpdateVisibility(contents, url); | 792 (*i)->UpdateVisibility(contents, url); |
821 | 793 |
822 // Check if the visibility of the action changed and notify if it did. | 794 // Check if the visibility of the action changed and notify if it did. |
823 ExtensionAction* action = (*i)->image_view()->page_action(); | 795 ExtensionAction* action = (*i)->image_view()->page_action(); |
824 if (old_visibility.find(action) == old_visibility.end() || | 796 if (old_visibility.find(action) == old_visibility.end() || |
825 old_visibility[action] != (*i)->IsVisible()) { | 797 old_visibility[action] != (*i)->IsVisible()) { |
826 NotificationService::current()->Notify( | 798 NotificationService::current()->Notify( |
827 NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | 799 NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
828 Source<ExtensionAction>(action), | 800 Source<ExtensionAction>(action), |
829 Details<TabContents>(contents)); | 801 Details<TabContents>(contents)); |
830 } | 802 } |
831 } | 803 } |
832 } | 804 } |
833 } | 805 } |
834 | 806 |
835 void LocationBarView::SetInfoText(const std::wstring& text, | |
836 ToolbarModel::InfoTextType text_type, | |
837 const std::wstring& tooltip_text) { | |
838 info_label_.SetVisible(!text.empty()); | |
839 info_label_.SetText(text); | |
840 if (text_type == ToolbarModel::INFO_EV_TEXT) | |
841 info_label_.SetColor(GetColor(true, SECURITY_TEXT)); | |
842 info_label_.SetTooltipText(tooltip_text); | |
843 } | |
844 | |
845 bool LocationBarView::ToggleVisibility(bool new_vis, View* view) { | 807 bool LocationBarView::ToggleVisibility(bool new_vis, View* view) { |
846 DCHECK(view); | 808 DCHECK(view); |
847 if (view->IsVisible() != new_vis) { | 809 if (view->IsVisible() == new_vis) |
848 view->SetVisible(new_vis); | 810 return false; |
849 return true; | 811 view->SetVisible(new_vis); |
850 } | 812 return true; |
851 return false; | |
852 } | 813 } |
853 | 814 |
854 #if defined(OS_WIN) | 815 #if defined(OS_WIN) |
855 void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) { | 816 void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) { |
856 UINT flags = 0; | 817 UINT flags = 0; |
857 if (event.IsControlDown()) | 818 if (event.IsControlDown()) |
858 flags |= MK_CONTROL; | 819 flags |= MK_CONTROL; |
859 if (event.IsShiftDown()) | 820 if (event.IsShiftDown()) |
860 flags |= MK_SHIFT; | 821 flags |= MK_SHIFT; |
861 if (event.IsLeftMouseButton()) | 822 if (event.IsLeftMouseButton()) |
862 flags |= MK_LBUTTON; | 823 flags |= MK_LBUTTON; |
863 if (event.IsMiddleMouseButton()) | 824 if (event.IsMiddleMouseButton()) |
864 flags |= MK_MBUTTON; | 825 flags |= MK_MBUTTON; |
865 if (event.IsRightMouseButton()) | 826 if (event.IsRightMouseButton()) |
866 flags |= MK_RBUTTON; | 827 flags |= MK_RBUTTON; |
867 | 828 |
868 gfx::Point screen_point(event.location()); | 829 gfx::Point screen_point(event.location()); |
869 ConvertPointToScreen(this, &screen_point); | 830 ConvertPointToScreen(this, &screen_point); |
870 | 831 |
871 location_entry_->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); | 832 location_entry_->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); |
872 } | 833 } |
873 #endif | 834 #endif |
874 | 835 |
| 836 void LocationBarView::ShowFirstRunBubbleInternal(bool use_OEM_bubble) { |
| 837 if (!location_entry_view_) |
| 838 return; |
| 839 if (!location_entry_view_->GetWidget()->IsActive()) { |
| 840 // The browser is no longer active. Let's not show the info bubble, this |
| 841 // would make the browser the active window again. |
| 842 return; |
| 843 } |
| 844 |
| 845 gfx::Point location; |
| 846 |
| 847 // If the UI layout is RTL, the coordinate system is not transformed and |
| 848 // therefore we need to adjust the X coordinate so that bubble appears on the |
| 849 // right hand side of the location bar. |
| 850 if (UILayoutIsRightToLeft()) |
| 851 location.Offset(width(), 0); |
| 852 views::View::ConvertPointToScreen(this, &location); |
| 853 |
| 854 // We try to guess that 20 pixels offset is a good place for the first |
| 855 // letter in the OmniBox. |
| 856 gfx::Rect bounds(location.x(), location.y(), 20, height()); |
| 857 |
| 858 // Moving the bounds "backwards" so that it appears within the location bar |
| 859 // if the UI layout is RTL. |
| 860 if (UILayoutIsRightToLeft()) |
| 861 bounds.set_x(location.x() - 20); |
| 862 |
| 863 #if defined(OS_WIN) |
| 864 FirstRunBubble::Show(profile_, GetWindow(), bounds, use_OEM_bubble); |
| 865 #else |
| 866 // First run bubble doesn't make sense for Chrome OS. |
| 867 #endif |
| 868 } |
| 869 |
875 bool LocationBarView::GetAccessibleName(std::wstring* name) { | 870 bool LocationBarView::GetAccessibleName(std::wstring* name) { |
876 DCHECK(name); | 871 DCHECK(name); |
877 | 872 |
878 if (!accessible_name_.empty()) { | 873 if (!accessible_name_.empty()) { |
879 name->assign(accessible_name_); | 874 name->assign(accessible_name_); |
880 return true; | 875 return true; |
881 } | 876 } |
882 return false; | 877 return false; |
883 } | 878 } |
884 | 879 |
885 bool LocationBarView::GetAccessibleRole(AccessibilityTypes::Role* role) { | 880 bool LocationBarView::GetAccessibleRole(AccessibilityTypes::Role* role) { |
886 DCHECK(role); | 881 DCHECK(role); |
887 | 882 |
888 *role = AccessibilityTypes::ROLE_GROUPING; | 883 *role = AccessibilityTypes::ROLE_GROUPING; |
889 return true; | 884 return true; |
890 } | 885 } |
891 | 886 |
892 void LocationBarView::SetAccessibleName(const std::wstring& name) { | 887 void LocationBarView::SetAccessibleName(const std::wstring& name) { |
893 accessible_name_.assign(name); | 888 accessible_name_.assign(name); |
894 } | 889 } |
895 | 890 |
| 891 // SecurityImageView------------------------------------------------------------ |
| 892 |
| 893 LocationBarView::SecurityImageView::SecurityImageView( |
| 894 const LocationBarView* parent) |
| 895 : parent_(parent) { |
| 896 SetSecurityIcon(0); |
| 897 } |
| 898 |
| 899 LocationBarView::SecurityImageView::~SecurityImageView() { |
| 900 } |
| 901 |
| 902 void LocationBarView::SecurityImageView::SetSecurityIcon(int icon_id) { |
| 903 if (icon_id == 0) { |
| 904 SetVisible(false); |
| 905 return; |
| 906 } |
| 907 |
| 908 SetImage(ResourceBundle::GetSharedInstance().GetBitmapNamed(icon_id)); |
| 909 SetVisible(true); |
| 910 } |
| 911 |
| 912 bool LocationBarView::SecurityImageView::OnMousePressed( |
| 913 const views::MouseEvent& event) { |
| 914 TabContents* tab = parent_->GetTabContents(); |
| 915 NavigationEntry* nav_entry = tab->controller().GetActiveEntry(); |
| 916 if (!nav_entry) { |
| 917 NOTREACHED(); |
| 918 return true; |
| 919 } |
| 920 tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true); |
| 921 return true; |
| 922 } |
| 923 |
896 // SelectedKeywordView ------------------------------------------------------- | 924 // SelectedKeywordView ------------------------------------------------------- |
897 | 925 |
898 // The background is drawn using HorizontalPainter. This is the | 926 // The background is drawn using HorizontalPainter. This is the |
899 // left/center/right image names. | 927 // left/center/right image names. |
900 static const int kBorderImages[] = { | 928 static const int kBorderImages[] = { |
901 IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_L, | 929 IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_L, |
902 IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_C, | 930 IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_C, |
903 IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_R }; | 931 IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_R }; |
904 | 932 |
905 // Insets around the label. | 933 // Insets around the label. |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 // AutocompleteEditViewWin::SkipDefaultKeyEventProcessing into this class so | 1152 // AutocompleteEditViewWin::SkipDefaultKeyEventProcessing into this class so |
1125 // it can be shared between Windows and Linux. | 1153 // it can be shared between Windows and Linux. |
1126 // For now, we just override back-space as it is the accelerator for back | 1154 // For now, we just override back-space as it is the accelerator for back |
1127 // navigation. | 1155 // navigation. |
1128 if (e.GetKeyCode() == base::VKEY_BACK) | 1156 if (e.GetKeyCode() == base::VKEY_BACK) |
1129 return true; | 1157 return true; |
1130 return false; | 1158 return false; |
1131 #endif | 1159 #endif |
1132 } | 1160 } |
1133 | 1161 |
1134 // ShowInfoBubbleTask----------------------------------------------------------- | |
1135 | |
1136 class LocationBarView::ShowInfoBubbleTask : public Task { | |
1137 public: | |
1138 explicit ShowInfoBubbleTask( | |
1139 LocationBarView::LocationBarImageView* image_view); | |
1140 virtual void Run(); | |
1141 void Cancel(); | |
1142 | |
1143 private: | |
1144 LocationBarView::LocationBarImageView* image_view_; | |
1145 bool cancelled_; | |
1146 | |
1147 DISALLOW_COPY_AND_ASSIGN(ShowInfoBubbleTask); | |
1148 }; | |
1149 | |
1150 LocationBarView::ShowInfoBubbleTask::ShowInfoBubbleTask( | |
1151 LocationBarView::LocationBarImageView* image_view) | |
1152 : image_view_(image_view), | |
1153 cancelled_(false) { | |
1154 } | |
1155 | |
1156 void LocationBarView::ShowInfoBubbleTask::Run() { | |
1157 if (cancelled_) | |
1158 return; | |
1159 | |
1160 if (!image_view_->GetWidget()->IsActive()) { | |
1161 // The browser is no longer active. Let's not show the info bubble, this | |
1162 // would make the browser the active window again. Also makes sure we NULL | |
1163 // show_info_bubble_task_ to prevent the SecurityImageView from keeping a | |
1164 // dangling pointer. | |
1165 image_view_->show_info_bubble_task_ = NULL; | |
1166 return; | |
1167 } | |
1168 | |
1169 image_view_->ShowInfoBubble(); | |
1170 } | |
1171 | |
1172 void LocationBarView::ShowInfoBubbleTask::Cancel() { | |
1173 cancelled_ = true; | |
1174 } | |
1175 | |
1176 // ----------------------------------------------------------------------------- | |
1177 | |
1178 void LocationBarView::ShowFirstRunBubbleInternal(bool use_OEM_bubble) { | |
1179 if (!location_entry_view_) | |
1180 return; | |
1181 if (!location_entry_view_->GetWidget()->IsActive()) { | |
1182 // The browser is no longer active. Let's not show the info bubble, this | |
1183 // would make the browser the active window again. | |
1184 return; | |
1185 } | |
1186 | |
1187 gfx::Point location; | |
1188 | |
1189 // If the UI layout is RTL, the coordinate system is not transformed and | |
1190 // therefore we need to adjust the X coordinate so that bubble appears on the | |
1191 // right hand side of the location bar. | |
1192 if (UILayoutIsRightToLeft()) | |
1193 location.Offset(width(), 0); | |
1194 views::View::ConvertPointToScreen(this, &location); | |
1195 | |
1196 // We try to guess that 20 pixels offset is a good place for the first | |
1197 // letter in the OmniBox. | |
1198 gfx::Rect bounds(location.x(), location.y(), 20, height()); | |
1199 | |
1200 // Moving the bounds "backwards" so that it appears within the location bar | |
1201 // if the UI layout is RTL. | |
1202 if (UILayoutIsRightToLeft()) | |
1203 bounds.set_x(location.x() - 20); | |
1204 | |
1205 #if defined(OS_WIN) | |
1206 FirstRunBubble::Show(profile_, GetWindow(), bounds, use_OEM_bubble); | |
1207 #else | |
1208 // First run bubble doesn't make sense for Chrome OS. | |
1209 #endif | |
1210 } | |
1211 | |
1212 // LocationBarImageView--------------------------------------------------------- | |
1213 | |
1214 LocationBarView::LocationBarImageView::LocationBarImageView( | |
1215 const BubblePositioner* bubble_positioner) | |
1216 : info_bubble_(NULL), | |
1217 show_info_bubble_task_(NULL), | |
1218 bubble_positioner_(bubble_positioner) { | |
1219 } | |
1220 | |
1221 LocationBarView::LocationBarImageView::~LocationBarImageView() { | |
1222 if (show_info_bubble_task_) | |
1223 show_info_bubble_task_->Cancel(); | |
1224 | |
1225 if (info_bubble_) | |
1226 info_bubble_->Close(); | |
1227 } | |
1228 | |
1229 void LocationBarView::LocationBarImageView::OnMouseMoved( | |
1230 const views::MouseEvent& event) { | |
1231 if (show_info_bubble_task_) { | |
1232 show_info_bubble_task_->Cancel(); | |
1233 show_info_bubble_task_ = NULL; | |
1234 } | |
1235 | |
1236 if (info_bubble_) { | |
1237 // If an info bubble is currently showing, nothing to do. | |
1238 return; | |
1239 } | |
1240 | |
1241 show_info_bubble_task_ = new ShowInfoBubbleTask(this); | |
1242 MessageLoop::current()->PostDelayedTask(FROM_HERE, show_info_bubble_task_, | |
1243 kInfoBubbleHoverDelayMs); | |
1244 } | |
1245 | |
1246 void LocationBarView::LocationBarImageView::OnMouseExited( | |
1247 const views::MouseEvent& event) { | |
1248 if (show_info_bubble_task_) { | |
1249 show_info_bubble_task_->Cancel(); | |
1250 show_info_bubble_task_ = NULL; | |
1251 } | |
1252 | |
1253 if (info_bubble_) | |
1254 info_bubble_->Close(); | |
1255 } | |
1256 | |
1257 void LocationBarView::LocationBarImageView::InfoBubbleClosing( | |
1258 InfoBubble* info_bubble, bool closed_by_escape) { | |
1259 info_bubble_ = NULL; | |
1260 } | |
1261 | |
1262 void LocationBarView::LocationBarImageView::ShowInfoBubbleImpl( | |
1263 const std::wstring& text, SkColor text_color) { | |
1264 gfx::Rect bounds(bubble_positioner_->GetLocationStackBounds()); | |
1265 gfx::Point location; | |
1266 views::View::ConvertPointToScreen(this, &location); | |
1267 bounds.set_x(location.x()); | |
1268 bounds.set_width(width()); | |
1269 | |
1270 views::Label* label = new views::Label(text); | |
1271 label->SetMultiLine(true); | |
1272 label->SetColor(text_color); | |
1273 label->SetFont(ResourceBundle::GetSharedInstance().GetFont( | |
1274 ResourceBundle::BaseFont).DeriveFont(2)); | |
1275 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
1276 label->SizeToFit(0); | |
1277 DCHECK(info_bubble_ == NULL); | |
1278 info_bubble_ = InfoBubble::Show(GetWindow(), bounds, label, this); | |
1279 show_info_bubble_task_ = NULL; | |
1280 } | |
1281 | |
1282 // SecurityImageView------------------------------------------------------------ | |
1283 | |
1284 // static | |
1285 SkBitmap* LocationBarView::SecurityImageView::lock_icon_ = NULL; | |
1286 SkBitmap* LocationBarView::SecurityImageView::warning_icon_ = NULL; | |
1287 | |
1288 LocationBarView::SecurityImageView::SecurityImageView( | |
1289 const LocationBarView* parent, | |
1290 Profile* profile, | |
1291 ToolbarModel* model, | |
1292 const BubblePositioner* bubble_positioner) | |
1293 : LocationBarImageView(bubble_positioner), | |
1294 parent_(parent), | |
1295 profile_(profile), | |
1296 model_(model) { | |
1297 if (!lock_icon_) { | |
1298 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
1299 lock_icon_ = rb.GetBitmapNamed(IDR_LOCK); | |
1300 warning_icon_ = rb.GetBitmapNamed(IDR_WARNING); | |
1301 } | |
1302 SetImageShown(LOCK); | |
1303 } | |
1304 | |
1305 LocationBarView::SecurityImageView::~SecurityImageView() { | |
1306 } | |
1307 | |
1308 void LocationBarView::SecurityImageView::SetImageShown(Image image) { | |
1309 switch (image) { | |
1310 case LOCK: | |
1311 SetImage(lock_icon_); | |
1312 break; | |
1313 case WARNING: | |
1314 SetImage(warning_icon_); | |
1315 break; | |
1316 default: | |
1317 NOTREACHED(); | |
1318 break; | |
1319 } | |
1320 } | |
1321 | |
1322 bool LocationBarView::SecurityImageView::OnMousePressed( | |
1323 const views::MouseEvent& event) { | |
1324 TabContents* tab = parent_->GetTabContents(); | |
1325 NavigationEntry* nav_entry = tab->controller().GetActiveEntry(); | |
1326 if (!nav_entry) { | |
1327 NOTREACHED(); | |
1328 return true; | |
1329 } | |
1330 tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true); | |
1331 return true; | |
1332 } | |
1333 | |
1334 void LocationBarView::SecurityImageView::ShowInfoBubble() { | |
1335 std::wstring text; | |
1336 model_->GetIconHoverText(&text); | |
1337 ShowInfoBubbleImpl(text, GetColor( | |
1338 model_->GetSecurityLevel() == ToolbarModel::SECURE, | |
1339 SECURITY_INFO_BUBBLE_TEXT)); | |
1340 } | |
1341 | |
1342 // ContentSettingImageView------------------------------------------------------ | 1162 // ContentSettingImageView------------------------------------------------------ |
1343 | 1163 |
1344 LocationBarView::ContentSettingImageView::ContentSettingImageView( | 1164 LocationBarView::ContentSettingImageView::ContentSettingImageView( |
1345 ContentSettingsType content_type, | 1165 ContentSettingsType content_type, |
1346 const LocationBarView* parent, | 1166 const LocationBarView* parent, |
1347 Profile* profile, | 1167 Profile* profile, |
1348 const BubblePositioner* bubble_positioner) | 1168 const BubblePositioner* bubble_positioner) |
1349 : content_setting_image_model_( | 1169 : content_setting_image_model_( |
1350 ContentSettingImageModel::CreateContentSettingImageModel( | 1170 ContentSettingImageModel::CreateContentSettingImageModel( |
1351 content_type)), | 1171 content_type)), |
1352 parent_(parent), | 1172 parent_(parent), |
1353 profile_(profile), | 1173 profile_(profile), |
1354 info_bubble_(NULL), | 1174 info_bubble_(NULL), |
1355 bubble_positioner_(bubble_positioner) { | 1175 bubble_positioner_(bubble_positioner) { |
1356 } | 1176 } |
1357 | 1177 |
1358 LocationBarView::ContentSettingImageView::~ContentSettingImageView() { | 1178 LocationBarView::ContentSettingImageView::~ContentSettingImageView() { |
1359 if (info_bubble_) | 1179 if (info_bubble_) |
1360 info_bubble_->Close(); | 1180 info_bubble_->Close(); |
1361 } | 1181 } |
1362 | 1182 |
1363 void LocationBarView::ContentSettingImageView::UpdateFromTabContents( | 1183 void LocationBarView::ContentSettingImageView::UpdateFromTabContents( |
1364 const TabContents* tab_contents) { | 1184 const TabContents* tab_contents) { |
1365 int old_icon = content_setting_image_model_->get_icon(); | 1185 int old_icon = content_setting_image_model_->get_icon(); |
1366 content_setting_image_model_->UpdateFromTabContents(tab_contents); | 1186 content_setting_image_model_->UpdateFromTabContents(tab_contents); |
1367 if (content_setting_image_model_->is_visible()) { | 1187 if (!content_setting_image_model_->is_visible()) { |
1368 if (old_icon != content_setting_image_model_->get_icon()) { | |
1369 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
1370 SetImage(rb.GetBitmapNamed(content_setting_image_model_->get_icon())); | |
1371 } | |
1372 SetTooltipText(UTF8ToWide(content_setting_image_model_->get_tooltip())); | |
1373 SetVisible(true); | |
1374 } else { | |
1375 SetVisible(false); | 1188 SetVisible(false); |
| 1189 return; |
1376 } | 1190 } |
| 1191 if (old_icon != content_setting_image_model_->get_icon()) { |
| 1192 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 1193 SetImage(rb.GetBitmapNamed(content_setting_image_model_->get_icon())); |
| 1194 } |
| 1195 SetTooltipText(UTF8ToWide(content_setting_image_model_->get_tooltip())); |
| 1196 SetVisible(true); |
1377 } | 1197 } |
1378 | 1198 |
1379 bool LocationBarView::ContentSettingImageView::OnMousePressed( | 1199 bool LocationBarView::ContentSettingImageView::OnMousePressed( |
1380 const views::MouseEvent& event) { | 1200 const views::MouseEvent& event) { |
1381 gfx::Rect bounds(bubble_positioner_->GetLocationStackBounds()); | 1201 gfx::Rect bounds(bubble_positioner_->GetLocationStackBounds()); |
1382 gfx::Point location; | 1202 gfx::Point location; |
1383 views::View::ConvertPointToScreen(this, &location); | 1203 views::View::ConvertPointToScreen(this, &location); |
1384 bounds.set_x(location.x()); | 1204 bounds.set_x(location.x()); |
1385 bounds.set_width(width()); | 1205 bounds.set_width(width()); |
1386 | 1206 |
(...skipping 27 matching lines...) Expand all Loading... |
1414 | 1234 |
1415 bool LocationBarView::ContentSettingImageView::CloseOnEscape() { | 1235 bool LocationBarView::ContentSettingImageView::CloseOnEscape() { |
1416 return true; | 1236 return true; |
1417 } | 1237 } |
1418 | 1238 |
1419 // PageActionImageView---------------------------------------------------------- | 1239 // PageActionImageView---------------------------------------------------------- |
1420 | 1240 |
1421 LocationBarView::PageActionImageView::PageActionImageView( | 1241 LocationBarView::PageActionImageView::PageActionImageView( |
1422 LocationBarView* owner, | 1242 LocationBarView* owner, |
1423 Profile* profile, | 1243 Profile* profile, |
1424 ExtensionAction* page_action, | 1244 ExtensionAction* page_action) |
1425 const BubblePositioner* bubble_positioner) | 1245 : owner_(owner), |
1426 : LocationBarImageView(bubble_positioner), | |
1427 owner_(owner), | |
1428 profile_(profile), | 1246 profile_(profile), |
1429 page_action_(page_action), | 1247 page_action_(page_action), |
1430 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), | 1248 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), |
1431 current_tab_id_(-1), | 1249 current_tab_id_(-1), |
1432 preview_enabled_(false), | 1250 preview_enabled_(false), |
1433 popup_(NULL) { | 1251 popup_(NULL) { |
1434 Extension* extension = profile->GetExtensionsService()->GetExtensionById( | 1252 Extension* extension = profile->GetExtensionsService()->GetExtensionById( |
1435 page_action->extension_id(), false); | 1253 page_action->extension_id(), false); |
1436 DCHECK(extension); | 1254 DCHECK(extension); |
1437 | 1255 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1498 inspect_with_devtools, | 1316 inspect_with_devtools, |
1499 ExtensionPopup::BUBBLE_CHROME, | 1317 ExtensionPopup::BUBBLE_CHROME, |
1500 this); // ExtensionPopup::Observer | 1318 this); // ExtensionPopup::Observer |
1501 } else { | 1319 } else { |
1502 ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( | 1320 ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( |
1503 profile_, page_action_->extension_id(), page_action_->id(), | 1321 profile_, page_action_->extension_id(), page_action_->id(), |
1504 current_tab_id_, current_url_.spec(), button); | 1322 current_tab_id_, current_url_.spec(), button); |
1505 } | 1323 } |
1506 } | 1324 } |
1507 | 1325 |
1508 void LocationBarView::PageActionImageView::OnMouseMoved( | |
1509 const views::MouseEvent& event) { | |
1510 // PageActionImageView uses normal tooltips rather than the info bubble, | |
1511 // so just do nothing here rather than letting LocationBarImageView start | |
1512 // its hover timer. | |
1513 } | |
1514 | |
1515 bool LocationBarView::PageActionImageView::OnMousePressed( | 1326 bool LocationBarView::PageActionImageView::OnMousePressed( |
1516 const views::MouseEvent& event) { | 1327 const views::MouseEvent& event) { |
1517 // We are interested in capturing mouse messages, but we want want to wait | 1328 // We are interested in capturing mouse messages, but we want want to wait |
1518 // until mouse-up because we might show a context menu. Doing so on mouse-down | 1329 // until mouse-up because we might show a context menu. Doing so on mouse-down |
1519 // causes weird bugs like http://crbug.com/33155. | 1330 // causes weird bugs like http://crbug.com/33155. |
1520 return true; | 1331 return true; |
1521 } | 1332 } |
1522 | 1333 |
1523 void LocationBarView::PageActionImageView::OnMouseReleased( | 1334 void LocationBarView::PageActionImageView::OnMouseReleased( |
1524 const views::MouseEvent& event, bool canceled) { | 1335 const views::MouseEvent& event, bool canceled) { |
(...skipping 20 matching lines...) Expand all Loading... |
1545 context_menu_contents_.reset(new ExtensionContextMenuModel( | 1356 context_menu_contents_.reset(new ExtensionContextMenuModel( |
1546 extension, browser, this)); | 1357 extension, browser, this)); |
1547 context_menu_menu_.reset(new views::Menu2(context_menu_contents_.get())); | 1358 context_menu_menu_.reset(new views::Menu2(context_menu_contents_.get())); |
1548 context_menu_menu_->RunContextMenuAt(point); | 1359 context_menu_menu_->RunContextMenuAt(point); |
1549 return; | 1360 return; |
1550 } | 1361 } |
1551 | 1362 |
1552 ExecuteAction(button, false); // inspect_with_devtools | 1363 ExecuteAction(button, false); // inspect_with_devtools |
1553 } | 1364 } |
1554 | 1365 |
1555 void LocationBarView::PageActionImageView::ShowInfoBubble() { | |
1556 ShowInfoBubbleImpl(ASCIIToWide(tooltip_), GetColor(false, TEXT)); | |
1557 } | |
1558 | |
1559 void LocationBarView::PageActionImageView::OnImageLoaded( | 1366 void LocationBarView::PageActionImageView::OnImageLoaded( |
1560 SkBitmap* image, ExtensionResource resource, int index) { | 1367 SkBitmap* image, ExtensionResource resource, int index) { |
1561 // We loaded icons()->size() icons, plus one extra if the page action had | 1368 // We loaded icons()->size() icons, plus one extra if the page action had |
1562 // a default icon. | 1369 // a default icon. |
1563 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); | 1370 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); |
1564 if (!page_action_->default_icon_path().empty()) | 1371 if (!page_action_->default_icon_path().empty()) |
1565 total_icons++; | 1372 total_icons++; |
1566 DCHECK(index < total_icons); | 1373 DCHECK(index < total_icons); |
1567 | 1374 |
1568 // Map the index of the loaded image back to its name. If we ever get an | 1375 // Map the index of the loaded image back to its name. If we ever get an |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1730 page_action_views_[i]->image_view()->ExecuteAction(kLeftMouseButton, | 1537 page_action_views_[i]->image_view()->ExecuteAction(kLeftMouseButton, |
1731 false); // inspect_with_devtools | 1538 false); // inspect_with_devtools |
1732 return; | 1539 return; |
1733 } | 1540 } |
1734 ++current; | 1541 ++current; |
1735 } | 1542 } |
1736 } | 1543 } |
1737 | 1544 |
1738 NOTREACHED(); | 1545 NOTREACHED(); |
1739 } | 1546 } |
OLD | NEW |