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/location_bar_view.h" | 5 #include "chrome/browser/views/location_bar/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 24 matching lines...) Expand all Loading... |
35 #include "grit/theme_resources.h" | 35 #include "grit/theme_resources.h" |
36 #include "views/drag_utils.h" | 36 #include "views/drag_utils.h" |
37 | 37 |
38 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
39 #include "chrome/browser/views/first_run_bubble.h" | 39 #include "chrome/browser/views/first_run_bubble.h" |
40 #endif | 40 #endif |
41 | 41 |
42 using views::View; | 42 using views::View; |
43 | 43 |
44 // static | 44 // static |
45 const int LocationBarView::kVertMargin = 2; | 45 const int LocationBarView::kNormalHorizontalEdgeThickness = 1; |
46 const int LocationBarView::kEdgeThickness = 2; | 46 const int LocationBarView::kVerticalEdgeThickness = 2; |
47 const int LocationBarView::kItemPadding = 3; | 47 const int LocationBarView::kItemPadding = 3; |
| 48 const int LocationBarView::kEdgeItemPadding = kItemPadding; |
| 49 const int LocationBarView::kBubblePadding = 1; |
48 const char LocationBarView::kViewClassName[] = | 50 const char LocationBarView::kViewClassName[] = |
49 "browser/views/location_bar/LocationBarView"; | 51 "browser/views/location_bar/LocationBarView"; |
50 | 52 |
51 // Convenience: Total space at the edges of the bar. | |
52 const int kEdgePadding = | |
53 LocationBarView::kEdgeThickness + LocationBarView::kItemPadding; | |
54 | |
55 // Padding before the start of a bubble. | |
56 static const int kBubblePadding = kEdgePadding - 1; | |
57 | |
58 // Padding between the location icon and the edit, if they're adjacent. | |
59 static const int kLocationIconEditPadding = LocationBarView::kItemPadding - 1; | |
60 | |
61 // Padding after the star. | |
62 static const int kStarPadding = kEdgePadding + 1; | |
63 | |
64 static const int kEVBubbleBackgroundImages[] = { | 53 static const int kEVBubbleBackgroundImages[] = { |
65 IDR_OMNIBOX_EV_BUBBLE_BACKGROUND_L, | 54 IDR_OMNIBOX_EV_BUBBLE_BACKGROUND_L, |
66 IDR_OMNIBOX_EV_BUBBLE_BACKGROUND_C, | 55 IDR_OMNIBOX_EV_BUBBLE_BACKGROUND_C, |
67 IDR_OMNIBOX_EV_BUBBLE_BACKGROUND_R, | 56 IDR_OMNIBOX_EV_BUBBLE_BACKGROUND_R, |
68 }; | 57 }; |
69 | 58 |
70 static const int kSelectedKeywordBackgroundImages[] = { | 59 static const int kSelectedKeywordBackgroundImages[] = { |
71 IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_L, | 60 IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_L, |
72 IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_C, | 61 IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_C, |
73 IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_R, | 62 IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_R, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 if (mode_ == POPUP) { | 107 if (mode_ == POPUP) { |
119 font_ = ResourceBundle::GetSharedInstance().GetFont( | 108 font_ = ResourceBundle::GetSharedInstance().GetFont( |
120 ResourceBundle::BaseFont); | 109 ResourceBundle::BaseFont); |
121 } else { | 110 } else { |
122 // Use a larger version of the system font. | 111 // Use a larger version of the system font. |
123 font_ = font_.DeriveFont(3); | 112 font_ = font_.DeriveFont(3); |
124 } | 113 } |
125 | 114 |
126 // If this makes the font too big, try to make it smaller so it will fit. | 115 // If this makes the font too big, try to make it smaller so it will fit. |
127 const int height = | 116 const int height = |
128 std::max(GetPreferredSize().height() - TopMargin() - kVertMargin, 0); | 117 std::max(GetPreferredSize().height() - (kVerticalEdgeThickness * 2), 0); |
129 while ((font_.height() > height) && (font_.FontSize() > 1)) | 118 while ((font_.height() > height) && (font_.FontSize() > 1)) |
130 font_ = font_.DeriveFont(-1); | 119 font_ = font_.DeriveFont(-1); |
131 | 120 |
132 location_icon_view_ = new LocationIconView(this); | 121 location_icon_view_ = new LocationIconView(this); |
133 AddChildView(location_icon_view_); | 122 AddChildView(location_icon_view_); |
134 location_icon_view_->SetVisible(true); | 123 location_icon_view_->SetVisible(true); |
135 location_icon_view_->SetDragController(this); | 124 location_icon_view_->SetDragController(this); |
136 | 125 |
137 ev_bubble_view_ = | 126 ev_bubble_view_ = |
138 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID, | 127 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID, |
(...skipping 27 matching lines...) Expand all Loading... |
166 l10n_util::GetStringUTF8(IDS_ACCNAME_LOCATION)); | 155 l10n_util::GetStringUTF8(IDS_ACCNAME_LOCATION)); |
167 #endif | 156 #endif |
168 location_entry_view_ = new views::NativeViewHost; | 157 location_entry_view_ = new views::NativeViewHost; |
169 location_entry_view_->SetID(VIEW_ID_AUTOCOMPLETE); | 158 location_entry_view_->SetID(VIEW_ID_AUTOCOMPLETE); |
170 AddChildView(location_entry_view_); | 159 AddChildView(location_entry_view_); |
171 location_entry_view_->set_focus_view(this); | 160 location_entry_view_->set_focus_view(this); |
172 location_entry_view_->Attach(location_entry_->GetNativeView()); | 161 location_entry_view_->Attach(location_entry_->GetNativeView()); |
173 location_entry_view_->SetAccessibleName( | 162 location_entry_view_->SetAccessibleName( |
174 l10n_util::GetString(IDS_ACCNAME_LOCATION)); | 163 l10n_util::GetString(IDS_ACCNAME_LOCATION)); |
175 | 164 |
176 selected_keyword_view_ = | 165 selected_keyword_view_ = new SelectedKeywordView( |
177 new SelectedKeywordView(kSelectedKeywordBackgroundImages, | 166 kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER, |
178 IDR_OMNIBOX_SEARCH, SK_ColorBLACK, profile_), | 167 GetColor(ToolbarModel::NONE, TEXT), profile_), |
179 AddChildView(selected_keyword_view_); | 168 AddChildView(selected_keyword_view_); |
180 selected_keyword_view_->SetFont(font_); | 169 selected_keyword_view_->SetFont(font_); |
181 selected_keyword_view_->SetVisible(false); | 170 selected_keyword_view_->SetVisible(false); |
182 | 171 |
183 SkColor dimmed_text = GetColor(ToolbarModel::NONE, DEEMPHASIZED_TEXT); | 172 SkColor dimmed_text = GetColor(ToolbarModel::NONE, DEEMPHASIZED_TEXT); |
184 | 173 |
185 keyword_hint_view_ = new KeywordHintView(profile_); | 174 keyword_hint_view_ = new KeywordHintView(profile_); |
186 AddChildView(keyword_hint_view_); | 175 AddChildView(keyword_hint_view_); |
187 keyword_hint_view_->SetVisible(false); | 176 keyword_hint_view_->SetVisible(false); |
188 keyword_hint_view_->SetFont(font_); | 177 keyword_hint_view_->SetFont(font_); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 | 371 |
383 gfx::Size LocationBarView::GetPreferredSize() { | 372 gfx::Size LocationBarView::GetPreferredSize() { |
384 return gfx::Size(0, GetThemeProvider()->GetBitmapNamed(mode_ == POPUP ? | 373 return gfx::Size(0, GetThemeProvider()->GetBitmapNamed(mode_ == POPUP ? |
385 IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C)->height()); | 374 IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C)->height()); |
386 } | 375 } |
387 | 376 |
388 void LocationBarView::Layout() { | 377 void LocationBarView::Layout() { |
389 if (!location_entry_.get()) | 378 if (!location_entry_.get()) |
390 return; | 379 return; |
391 | 380 |
392 int entry_width = width() - (star_view_ ? kStarPadding : kEdgePadding); | 381 // TODO(sky): baseline layout. |
| 382 int location_y = kVerticalEdgeThickness; |
| 383 int location_height = height() - (kVerticalEdgeThickness * 2); |
| 384 |
| 385 // The edge stroke is 1 px thick. In popup mode, the edges are drawn by the |
| 386 // omnibox' parent, so there isn't any edge to account for at all. |
| 387 const int kEdgeThickness = (mode_ == NORMAL) ? |
| 388 kNormalHorizontalEdgeThickness : 0; |
| 389 // The edit has 1 px of horizontal whitespace inside it before the text. |
| 390 const int kEditInternalSpace = 1; |
| 391 // The space between an item and the edit is the normal item space, minus the |
| 392 // edit's built-in space (so the apparent space will be the same). |
| 393 const int kItemEditPadding = |
| 394 LocationBarView::kItemPadding - kEditInternalSpace; |
| 395 const int kEdgeEditPadding = |
| 396 LocationBarView::kEdgeItemPadding - kEditInternalSpace; |
| 397 |
| 398 // Start by reserving the padding at the right edge. |
| 399 int entry_width = width() - kEdgeThickness - kEdgeItemPadding; |
393 | 400 |
394 // |location_icon_view_| is visible except when |ev_bubble_view_| or | 401 // |location_icon_view_| is visible except when |ev_bubble_view_| or |
395 // |selected_keyword_view_| are visible. | 402 // |selected_keyword_view_| are visible. |
396 int location_icon_width = 0; | 403 int location_icon_width = 0; |
397 int ev_bubble_width = 0; | 404 int ev_bubble_width = 0; |
398 location_icon_view_->SetVisible(false); | 405 location_icon_view_->SetVisible(false); |
399 ev_bubble_view_->SetVisible(false); | 406 ev_bubble_view_->SetVisible(false); |
400 const std::wstring keyword(location_entry_->model()->keyword()); | 407 const std::wstring keyword(location_entry_->model()->keyword()); |
401 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint()); | 408 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint()); |
402 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint; | 409 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint; |
403 if (show_selected_keyword) { | 410 if (show_selected_keyword) { |
404 entry_width -= kEdgePadding; // Assume the keyword might be hidden. | 411 // Assume the keyword might be hidden. |
| 412 entry_width -= (kEdgeThickness + kEdgeEditPadding); |
405 } else if (model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { | 413 } else if (model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { |
406 ev_bubble_view_->SetVisible(true); | 414 ev_bubble_view_->SetVisible(true); |
407 ev_bubble_view_->SetLabel(model_->GetEVCertName()); | 415 ev_bubble_view_->SetLabel(model_->GetEVCertName()); |
408 ev_bubble_width = ev_bubble_view_->GetPreferredSize().width(); | 416 ev_bubble_width = ev_bubble_view_->GetPreferredSize().width(); |
409 // We'll adjust this width and take it out of |entry_width| below. | 417 // We'll adjust this width and take it out of |entry_width| below. |
410 } else { | 418 } else { |
411 location_icon_view_->SetVisible(true); | 419 location_icon_view_->SetVisible(true); |
412 location_icon_width = location_icon_view_->GetPreferredSize().width(); | 420 location_icon_width = location_icon_view_->GetPreferredSize().width(); |
413 entry_width -= | 421 entry_width -= (kEdgeThickness + kEdgeItemPadding + location_icon_width + |
414 kEdgePadding + location_icon_width + kLocationIconEditPadding; | 422 kItemEditPadding); |
415 } | 423 } |
416 | 424 |
417 if (star_view_) | 425 if (star_view_) |
418 entry_width -= star_view_->GetPreferredSize().width() + kItemPadding; | 426 entry_width -= star_view_->GetPreferredSize().width() + kItemPadding; |
419 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 427 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
420 i != page_action_views_.end(); ++i) { | 428 i != page_action_views_.end(); ++i) { |
421 if ((*i)->IsVisible()) | 429 if ((*i)->IsVisible()) |
422 entry_width -= (*i)->GetPreferredSize().width() + kItemPadding; | 430 entry_width -= ((*i)->GetPreferredSize().width() + kItemPadding); |
423 } | 431 } |
424 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 432 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
425 i != content_setting_views_.end(); ++i) { | 433 i != content_setting_views_.end(); ++i) { |
426 if ((*i)->IsVisible()) | 434 if ((*i)->IsVisible()) |
427 entry_width -= (*i)->GetPreferredSize().width() + kItemPadding; | 435 entry_width -= ((*i)->GetPreferredSize().width() + kItemPadding); |
428 } | 436 } |
| 437 // The gap between the edit and whatever is to its right is shortened. |
| 438 entry_width += kEditInternalSpace; |
429 | 439 |
430 // Size the EV bubble. We do this after taking the star/page actions/content | 440 // Size the EV bubble. We do this after taking the star/page actions/content |
431 // settings out of |entry_width| so we won't take too much space. | 441 // settings out of |entry_width| so we won't take too much space. |
432 if (ev_bubble_width) { | 442 if (ev_bubble_width) { |
433 // Try to elide the bubble to be no larger than half the total available | 443 // Try to elide the bubble to be no larger than half the total available |
434 // space, but never elide it any smaller than 150 px. | 444 // space, but never elide it any smaller than 150 px. |
435 static const int kMinElidedBubbleWidth = 150; | 445 static const int kMinElidedBubbleWidth = 150; |
436 static const double kMaxBubbleFraction = 0.5; | 446 static const double kMaxBubbleFraction = 0.5; |
| 447 const int total_padding = |
| 448 kEdgeThickness + kBubblePadding + kItemEditPadding; |
437 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth, | 449 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth, |
438 static_cast<int>((entry_width - kBubblePadding - kItemPadding) * | 450 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction))); |
439 kMaxBubbleFraction))); | 451 entry_width -= (total_padding + ev_bubble_width); |
440 | |
441 entry_width -= kBubblePadding + ev_bubble_width + kItemPadding; | |
442 } | 452 } |
443 | 453 |
444 #if defined(OS_WIN) | 454 #if defined(OS_WIN) |
445 RECT formatting_rect; | 455 RECT formatting_rect; |
446 location_entry_->GetRect(&formatting_rect); | 456 location_entry_->GetRect(&formatting_rect); |
447 RECT edit_bounds; | 457 RECT edit_bounds; |
448 location_entry_->GetClientRect(&edit_bounds); | 458 location_entry_->GetClientRect(&edit_bounds); |
449 int max_edit_width = entry_width - formatting_rect.left - | 459 int max_edit_width = entry_width - formatting_rect.left - |
450 (edit_bounds.right - formatting_rect.right); | 460 (edit_bounds.right - formatting_rect.right); |
451 #else | 461 #else |
452 int max_edit_width = entry_width; | 462 int max_edit_width = entry_width; |
453 #endif | 463 #endif |
454 | 464 |
455 if (max_edit_width < 0) | 465 if (max_edit_width < 0) |
456 return; | 466 return; |
457 const int available_width = AvailableWidth(max_edit_width); | 467 const int available_width = AvailableWidth(max_edit_width); |
458 | 468 |
459 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint; | 469 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint; |
460 selected_keyword_view_->SetVisible(show_selected_keyword); | 470 selected_keyword_view_->SetVisible(show_selected_keyword); |
461 keyword_hint_view_->SetVisible(show_keyword_hint); | 471 keyword_hint_view_->SetVisible(show_keyword_hint); |
462 if (show_selected_keyword) { | 472 if (show_selected_keyword) { |
463 if (selected_keyword_view_->keyword() != keyword) { | 473 if (selected_keyword_view_->keyword() != keyword) { |
464 selected_keyword_view_->SetKeyword(keyword); | 474 selected_keyword_view_->SetKeyword(keyword); |
465 | |
466 const TemplateURL* template_url = | 475 const TemplateURL* template_url = |
467 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); | 476 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); |
468 if (template_url && template_url->IsExtensionKeyword()) { | 477 if (template_url && template_url->IsExtensionKeyword()) { |
469 const SkBitmap& bitmap = profile_->GetExtensionsService()-> | 478 const SkBitmap& bitmap = profile_->GetExtensionsService()-> |
470 GetOmniboxIcon(template_url->GetExtensionId()); | 479 GetOmniboxIcon(template_url->GetExtensionId()); |
471 selected_keyword_view_->SetImage(bitmap); | 480 selected_keyword_view_->SetImage(bitmap); |
472 } else { | 481 } else { |
473 selected_keyword_view_->SetImage(*ResourceBundle::GetSharedInstance(). | 482 selected_keyword_view_->SetImage(*ResourceBundle::GetSharedInstance(). |
474 GetBitmapNamed(IDR_OMNIBOX_SEARCH)); | 483 GetBitmapNamed(IDR_OMNIBOX_SEARCH)); |
475 } | 484 } |
476 } | 485 } |
477 } else if (show_keyword_hint) { | 486 } else if (show_keyword_hint) { |
478 if (keyword_hint_view_->keyword() != keyword) | 487 if (keyword_hint_view_->keyword() != keyword) |
479 keyword_hint_view_->SetKeyword(keyword); | 488 keyword_hint_view_->SetKeyword(keyword); |
480 } | 489 } |
481 | 490 |
482 // TODO(sky): baseline layout. | |
483 int location_y = TopMargin(); | |
484 int location_height = std::max(height() - location_y - kVertMargin, 0); | |
485 | |
486 // Lay out items to the right of the edit field. | 491 // Lay out items to the right of the edit field. |
487 int offset = width(); | 492 int offset = width() - kEdgeThickness - kEdgeItemPadding; |
488 if (star_view_) { | 493 if (star_view_) { |
489 offset -= kStarPadding; | |
490 int star_width = star_view_->GetPreferredSize().width(); | 494 int star_width = star_view_->GetPreferredSize().width(); |
491 offset -= star_width; | 495 offset -= star_width; |
492 star_view_->SetBounds(offset, location_y, star_width, location_height); | 496 star_view_->SetBounds(offset, location_y, star_width, location_height); |
493 offset -= kItemPadding; | 497 offset -= kItemPadding; |
494 } else { | |
495 offset -= kEdgePadding; | |
496 } | 498 } |
497 | 499 |
498 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 500 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
499 i != page_action_views_.end(); ++i) { | 501 i != page_action_views_.end(); ++i) { |
500 if ((*i)->IsVisible()) { | 502 if ((*i)->IsVisible()) { |
501 int page_action_width = (*i)->GetPreferredSize().width(); | 503 int page_action_width = (*i)->GetPreferredSize().width(); |
502 offset -= page_action_width; | 504 offset -= page_action_width; |
503 (*i)->SetBounds(offset, location_y, page_action_width, location_height); | 505 (*i)->SetBounds(offset, location_y, page_action_width, location_height); |
504 offset -= kItemPadding; | 506 offset -= kItemPadding; |
505 } | 507 } |
506 } | 508 } |
507 // We use a reverse_iterator here because we're laying out the views from | 509 // We use a reverse_iterator here because we're laying out the views from |
508 // right to left but in the vector they're ordered left to right. | 510 // right to left but in the vector they're ordered left to right. |
509 for (ContentSettingViews::const_reverse_iterator | 511 for (ContentSettingViews::const_reverse_iterator |
510 i(content_setting_views_.rbegin()); i != content_setting_views_.rend(); | 512 i(content_setting_views_.rbegin()); i != content_setting_views_.rend(); |
511 ++i) { | 513 ++i) { |
512 if ((*i)->IsVisible()) { | 514 if ((*i)->IsVisible()) { |
513 int content_blocked_width = (*i)->GetPreferredSize().width(); | 515 int content_blocked_width = (*i)->GetPreferredSize().width(); |
514 offset -= content_blocked_width; | 516 offset -= content_blocked_width; |
515 (*i)->SetBounds(offset, location_y, content_blocked_width, | 517 (*i)->SetBounds(offset, location_y, content_blocked_width, |
516 location_height); | 518 location_height); |
517 offset -= kItemPadding; | 519 offset -= kItemPadding; |
518 } | 520 } |
519 } | 521 } |
520 | 522 |
521 // Now lay out items to the left of the edit field. | 523 // Now lay out items to the left of the edit field. |
522 if (location_icon_view_->IsVisible()) { | 524 if (location_icon_view_->IsVisible()) { |
523 location_icon_view_->SetBounds(kEdgePadding, location_y, | 525 location_icon_view_->SetBounds(kEdgeThickness + kEdgeItemPadding, |
524 location_icon_width, location_height); | 526 location_y, location_icon_width, location_height); |
525 offset = location_icon_view_->bounds().right() + kLocationIconEditPadding; | 527 offset = location_icon_view_->bounds().right() + kItemEditPadding; |
526 } else if (ev_bubble_view_->IsVisible()) { | 528 } else if (ev_bubble_view_->IsVisible()) { |
527 ev_bubble_view_->SetBounds(kBubblePadding, location_y, ev_bubble_width, | 529 ev_bubble_view_->SetBounds(kEdgeThickness + kBubblePadding, |
528 location_height); | 530 location_y + kBubblePadding, ev_bubble_width, |
529 offset = ev_bubble_view_->bounds().right() + kItemPadding; | 531 ev_bubble_view_->GetPreferredSize().height()); |
| 532 offset = ev_bubble_view_->bounds().right() + kItemEditPadding; |
530 } else { | 533 } else { |
531 offset = show_selected_keyword ? kBubblePadding : kEdgePadding; | 534 offset = kEdgeThickness + |
| 535 (show_selected_keyword ? kBubblePadding : kEdgeEditPadding); |
532 } | 536 } |
533 | 537 |
534 // Now lay out the edit field and views that autocollapse to give it more | 538 // Now lay out the edit field and views that autocollapse to give it more |
535 // room. | 539 // room. |
536 gfx::Rect location_bounds(offset, location_y, entry_width, location_height); | 540 gfx::Rect location_bounds(offset, location_y, entry_width, location_height); |
537 if (show_selected_keyword) { | 541 if (show_selected_keyword) { |
538 LayoutView(true, selected_keyword_view_, available_width, &location_bounds); | 542 selected_keyword_view_->SetBounds(0, location_y + kBubblePadding, 0, |
539 if (!selected_keyword_view_->IsVisible()) { | 543 selected_keyword_view_->GetPreferredSize().height()); |
540 location_bounds.set_x( | 544 LayoutView(selected_keyword_view_, kItemEditPadding, available_width, |
541 location_bounds.x() + kEdgePadding - kBubblePadding); | 545 true, &location_bounds); |
| 546 location_bounds.set_x(selected_keyword_view_->IsVisible() ? |
| 547 (offset + selected_keyword_view_->width() + kItemEditPadding) : |
| 548 (kEdgeThickness + kEdgeEditPadding)); |
| 549 } else if (show_keyword_hint) { |
| 550 keyword_hint_view_->SetBounds(0, location_y, 0, location_height); |
| 551 // Tricky: |entry_width| has already been enlarged by |kEditInternalSpace|. |
| 552 // But if we add a trailing view, it needs to have that enlargement be to |
| 553 // its left. So we undo the enlargement, then include it in the padding for |
| 554 // the added view. |
| 555 location_bounds.Inset(0, 0, kEditInternalSpace, 0); |
| 556 LayoutView(keyword_hint_view_, kItemEditPadding, available_width, false, |
| 557 &location_bounds); |
| 558 if (!keyword_hint_view_->IsVisible()) { |
| 559 // Put back the enlargement that we undid above. |
| 560 location_bounds.Inset(0, 0, -kEditInternalSpace, 0); |
542 } | 561 } |
543 } else if (show_keyword_hint) { | |
544 LayoutView(false, keyword_hint_view_, available_width, &location_bounds); | |
545 } | 562 } |
546 | 563 |
547 location_entry_view_->SetBounds(location_bounds); | 564 location_entry_view_->SetBounds(location_bounds); |
548 } | 565 } |
549 | 566 |
550 void LocationBarView::Paint(gfx::Canvas* canvas) { | 567 void LocationBarView::Paint(gfx::Canvas* canvas) { |
551 View::Paint(canvas); | 568 View::Paint(canvas); |
552 | 569 |
553 if (painter_.get()) { | 570 if (painter_.get()) { |
554 painter_->Paint(width(), height(), canvas); | 571 painter_->Paint(width(), height(), canvas); |
555 } else if (mode_ == POPUP) { | 572 } else if (mode_ == POPUP) { |
556 canvas->TileImageInt(*GetThemeProvider()->GetBitmapNamed( | 573 canvas->TileImageInt(*GetThemeProvider()->GetBitmapNamed( |
557 IDR_LOCATIONBG_POPUPMODE_CENTER), 0, 0, 0, 0, width(), height()); | 574 IDR_LOCATIONBG_POPUPMODE_CENTER), 0, 0, 0, 0, width(), height()); |
558 } | 575 } |
559 // When used in the app launcher, don't draw a border, the LocationBarView has | 576 // When used in the app launcher, don't draw a border, the LocationBarView has |
560 // its own views::Border. | 577 // its own views::Border. |
561 | 578 |
562 // Draw the background color so that the graphical elements at the edges | 579 // Draw the background color so that the graphical elements at the edges |
563 // appear over the correct color. (The edit draws its own background, so this | 580 // appear over the correct color. (The edit draws its own background, so this |
564 // isn't important for that.) | 581 // isn't important for that.) |
565 // TODO(pkasting): We need images that are transparent in the middle, so we | 582 // TODO(pkasting): We need images that are transparent in the middle, so we |
566 // can draw the border images over the background color instead of the | 583 // can draw the border images over the background color instead of the |
567 // reverse; this antialiases better (see comments in | 584 // reverse; this antialiases better (see comments in |
568 // AutocompletePopupContentsView::Paint()). | 585 // AutocompletePopupContentsView::Paint()). |
569 gfx::Rect bounds(GetLocalBounds(false)); | 586 gfx::Rect bounds(GetLocalBounds(false)); |
570 bounds.Inset(0, TopMargin(), 0, kVertMargin); | 587 bounds.Inset(0, kVerticalEdgeThickness); |
571 SkColor color(GetColor(ToolbarModel::NONE, BACKGROUND)); | 588 SkColor color(GetColor(ToolbarModel::NONE, BACKGROUND)); |
572 if (mode_ == NORMAL) { | 589 if (mode_ == NORMAL) { |
573 SkPaint paint; | 590 SkPaint paint; |
574 paint.setColor(color); | 591 paint.setColor(color); |
575 paint.setStyle(SkPaint::kFill_Style); | 592 paint.setStyle(SkPaint::kFill_Style); |
576 paint.setAntiAlias(true); | 593 paint.setAntiAlias(true); |
577 // The round corners of the omnibox match the round corners of the dropdown | 594 // The round corners of the omnibox match the round corners of the dropdown |
578 // below, and all our other bubbles. | 595 // below, and all our other bubbles. |
579 const SkScalar radius(SkIntToScalar(BubbleBorder::GetCornerRadius())); | 596 const SkScalar radius(SkIntToScalar(BubbleBorder::GetCornerRadius())); |
580 bounds.Inset(kEdgeThickness, 0); | 597 bounds.Inset(kNormalHorizontalEdgeThickness, 0); |
581 canvas->AsCanvasSkia()->drawRoundRect(gfx::RectToSkRect(bounds), radius, | 598 canvas->AsCanvasSkia()->drawRoundRect(gfx::RectToSkRect(bounds), radius, |
582 radius, paint); | 599 radius, paint); |
583 } else { | 600 } else { |
584 canvas->FillRectInt(color, bounds.x(), bounds.y(), bounds.width(), | 601 canvas->FillRectInt(color, bounds.x(), bounds.y(), bounds.width(), |
585 bounds.height()); | 602 bounds.height()); |
586 } | 603 } |
587 | 604 |
588 if (show_focus_rect_ && HasFocus()) { | 605 if (show_focus_rect_ && HasFocus()) { |
589 gfx::Rect r = location_entry_view_->bounds(); | 606 gfx::Rect r = location_entry_view_->bounds(); |
590 #if defined(OS_WIN) | 607 #if defined(OS_WIN) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 DCHECK(delegate_->GetTabContents()); | 729 DCHECK(delegate_->GetTabContents()); |
713 return delegate_->GetTabContents()->GetFavIcon(); | 730 return delegate_->GetTabContents()->GetFavIcon(); |
714 } | 731 } |
715 | 732 |
716 std::wstring LocationBarView::GetTitle() const { | 733 std::wstring LocationBarView::GetTitle() const { |
717 DCHECK(delegate_); | 734 DCHECK(delegate_); |
718 DCHECK(delegate_->GetTabContents()); | 735 DCHECK(delegate_->GetTabContents()); |
719 return UTF16ToWideHack(delegate_->GetTabContents()->GetTitle()); | 736 return UTF16ToWideHack(delegate_->GetTabContents()->GetTitle()); |
720 } | 737 } |
721 | 738 |
722 int LocationBarView::TopMargin() const { | |
723 return std::min(kVertMargin, height()); | |
724 } | |
725 | |
726 int LocationBarView::AvailableWidth(int location_bar_width) { | 739 int LocationBarView::AvailableWidth(int location_bar_width) { |
727 #if defined(OS_WIN) | 740 #if defined(OS_WIN) |
728 // Use font_.GetStringWidth() instead of | 741 // Use font_.GetStringWidth() instead of |
729 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 742 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
730 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 743 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, |
731 // PosFromChar(i) might return 0 when i is greater than 1. | 744 // PosFromChar(i) might return 0 when i is greater than 1. |
732 return std::max( | 745 return std::max( |
733 location_bar_width - font_.GetStringWidth(location_entry_->GetText()), 0); | 746 location_bar_width - font_.GetStringWidth(location_entry_->GetText()), 0); |
734 #else | 747 #else |
735 return location_bar_width - location_entry_->TextWidth(); | 748 return location_bar_width - location_entry_->TextWidth(); |
736 #endif | 749 #endif |
737 } | 750 } |
738 | 751 void LocationBarView::LayoutView(views::View* view, |
739 bool LocationBarView::UsePref(int pref_width, int available_width) { | 752 int padding, |
740 return (pref_width + kItemPadding <= available_width); | |
741 } | |
742 | |
743 void LocationBarView::LayoutView(bool leading, | |
744 views::View* view, | |
745 int available_width, | 753 int available_width, |
| 754 bool leading, |
746 gfx::Rect* bounds) { | 755 gfx::Rect* bounds) { |
747 DCHECK(view && bounds); | 756 DCHECK(view && bounds); |
748 gfx::Size view_size = view->GetPreferredSize(); | 757 gfx::Size view_size = view->GetPreferredSize(); |
749 if (!UsePref(view_size.width(), available_width)) | 758 if ((view_size.width() + padding) > available_width) |
750 view_size = view->GetMinimumSize(); | 759 view_size = view->GetMinimumSize(); |
751 if (view_size.width() + kItemPadding >= bounds->width()) { | 760 int desired_width = view_size.width() + padding; |
752 view->SetVisible(false); | 761 view->SetVisible(desired_width < bounds->width()); |
753 return; | 762 if (view->IsVisible()) { |
| 763 view->SetBounds( |
| 764 leading ? bounds->x() : (bounds->right() - view_size.width()), |
| 765 view->y(), view_size.width(), view->height()); |
| 766 bounds->set_width(bounds->width() - desired_width); |
754 } | 767 } |
755 if (leading) { | |
756 view->SetBounds(bounds->x(), bounds->y(), view_size.width(), | |
757 bounds->height()); | |
758 bounds->Offset(view_size.width() + kItemPadding, 0); | |
759 } else { | |
760 view->SetBounds(bounds->right() - view_size.width(), bounds->y(), | |
761 view_size.width(), bounds->height()); | |
762 } | |
763 bounds->set_width(bounds->width() - view_size.width() - kItemPadding); | |
764 view->SetVisible(true); | |
765 } | 768 } |
766 | 769 |
767 void LocationBarView::RefreshContentSettingViews() { | 770 void LocationBarView::RefreshContentSettingViews() { |
768 const TabContents* tab_contents = delegate_->GetTabContents(); | 771 const TabContents* tab_contents = delegate_->GetTabContents(); |
769 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 772 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
770 i != content_setting_views_.end(); ++i) { | 773 i != content_setting_views_.end(); ++i) { |
771 (*i)->UpdateFromTabContents( | 774 (*i)->UpdateFromTabContents( |
772 model_->input_in_progress() ? NULL : tab_contents); | 775 model_->input_in_progress() ? NULL : tab_contents); |
773 } | 776 } |
774 } | 777 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 | 864 |
862 void LocationBarView::ShowFirstRunBubbleInternal( | 865 void LocationBarView::ShowFirstRunBubbleInternal( |
863 FirstRun::BubbleType bubble_type) { | 866 FirstRun::BubbleType bubble_type) { |
864 #if defined(OS_WIN) // First run bubble doesn't make sense for Chrome OS. | 867 #if defined(OS_WIN) // First run bubble doesn't make sense for Chrome OS. |
865 // If the browser is no longer active, let's not show the info bubble, as this | 868 // If the browser is no longer active, let's not show the info bubble, as this |
866 // would make the browser the active window again. | 869 // would make the browser the active window again. |
867 if (!location_entry_view_ || !location_entry_view_->GetWidget()->IsActive()) | 870 if (!location_entry_view_ || !location_entry_view_->GetWidget()->IsActive()) |
868 return; | 871 return; |
869 | 872 |
870 // Point at the start of the edit control; adjust to look as good as possible. | 873 // Point at the start of the edit control; adjust to look as good as possible. |
871 const int kXOffset = 6; // Text looks like it actually starts 6 px in. | 874 const int kXOffset = kNormalHorizontalEdgeThickness + kEdgeItemPadding + |
872 const int kYOffset = -4; // Point into the omnibox, not just at its edge. | 875 ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 876 IDR_OMNIBOX_HTTP)->width() + kItemPadding; |
| 877 const int kYOffset = -(kVerticalEdgeThickness + 2); |
873 gfx::Point origin(location_entry_view_->bounds().x() + kXOffset, | 878 gfx::Point origin(location_entry_view_->bounds().x() + kXOffset, |
874 y() + height() + kYOffset); | 879 y() + height() + kYOffset); |
875 // If the UI layout is RTL, the coordinate system is not transformed and | 880 // If the UI layout is RTL, the coordinate system is not transformed and |
876 // therefore we need to adjust the X coordinate so that bubble appears on the | 881 // therefore we need to adjust the X coordinate so that bubble appears on the |
877 // right hand side of the location bar. | 882 // right hand side of the location bar. |
878 if (base::i18n::IsRTL()) | 883 if (base::i18n::IsRTL()) |
879 origin.set_x(width() - origin.x()); | 884 origin.set_x(width() - origin.x()); |
880 views::View::ConvertPointToScreen(this, &origin); | 885 views::View::ConvertPointToScreen(this, &origin); |
881 FirstRunBubble::Show(profile_, GetWidget(), gfx::Rect(origin, gfx::Size()), | 886 FirstRunBubble::Show(profile_, GetWidget(), gfx::Rect(origin, gfx::Size()), |
882 BubbleBorder::TOP_LEFT, bubble_type); | 887 BubbleBorder::TOP_LEFT, bubble_type); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 | 1048 |
1044 NOTREACHED(); | 1049 NOTREACHED(); |
1045 } | 1050 } |
1046 | 1051 |
1047 void LocationBarView::OnTemplateURLModelChanged() { | 1052 void LocationBarView::OnTemplateURLModelChanged() { |
1048 template_url_model_->RemoveObserver(this); | 1053 template_url_model_->RemoveObserver(this); |
1049 template_url_model_ = NULL; | 1054 template_url_model_ = NULL; |
1050 ShowFirstRunBubble(bubble_type_); | 1055 ShowFirstRunBubble(bubble_type_); |
1051 } | 1056 } |
1052 | 1057 |
OLD | NEW |