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

Side by Side Diff: chrome/browser/views/location_bar/location_bar_view.cc

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

Powered by Google App Engine
This is Rietveld 408576698