Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
| 44 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
| 45 #include "content/public/browser/render_widget_host_view.h" | 45 #include "content/public/browser/render_widget_host_view.h" |
| 46 #include "content/public/browser/web_contents.h" | 46 #include "content/public/browser/web_contents.h" |
| 47 #include "grit/generated_resources.h" | 47 #include "grit/generated_resources.h" |
| 48 #include "grit/theme_resources.h" | 48 #include "grit/theme_resources.h" |
| 49 #include "grit/theme_resources_standard.h" | 49 #include "grit/theme_resources_standard.h" |
| 50 #include "ui/base/accessibility/accessible_view_state.h" | 50 #include "ui/base/accessibility/accessible_view_state.h" |
| 51 #include "ui/base/dragdrop/drag_drop_types.h" | 51 #include "ui/base/dragdrop/drag_drop_types.h" |
| 52 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
| 53 #include "ui/base/layout.h" | |
| 53 #include "ui/base/resource/resource_bundle.h" | 54 #include "ui/base/resource/resource_bundle.h" |
| 54 #include "ui/base/theme_provider.h" | 55 #include "ui/base/theme_provider.h" |
| 55 #include "ui/gfx/canvas.h" | 56 #include "ui/gfx/canvas.h" |
| 56 #include "ui/gfx/color_utils.h" | 57 #include "ui/gfx/color_utils.h" |
| 57 #include "ui/gfx/image/image.h" | 58 #include "ui/gfx/image/image.h" |
| 58 #include "ui/gfx/skia_util.h" | 59 #include "ui/gfx/skia_util.h" |
| 59 #include "ui/views/button_drag_utils.h" | 60 #include "ui/views/button_drag_utils.h" |
| 60 #include "ui/views/controls/label.h" | 61 #include "ui/views/controls/label.h" |
| 61 | 62 |
| 62 #if !defined(OS_CHROMEOS) | 63 #if !defined(OS_CHROMEOS) |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 82 return static_cast<OmniboxViewViews*>(view); | 83 return static_cast<OmniboxViewViews*>(view); |
| 83 } | 84 } |
| 84 | 85 |
| 85 // Height of the location bar's round corner region. | 86 // Height of the location bar's round corner region. |
| 86 const int kBorderRoundCornerHeight = 5; | 87 const int kBorderRoundCornerHeight = 5; |
| 87 // Width of location bar's round corner region. | 88 // Width of location bar's round corner region. |
| 88 const int kBorderRoundCornerWidth = 4; | 89 const int kBorderRoundCornerWidth = 4; |
| 89 // Radius of the round corners inside the location bar. | 90 // Radius of the round corners inside the location bar. |
| 90 const int kBorderCornerRadius = 2; | 91 const int kBorderCornerRadius = 2; |
| 91 | 92 |
| 93 const int kDesktopItemPadding = 3; | |
| 94 const int kDesktopEdgeItemPadding = kDesktopItemPadding; | |
| 95 | |
| 96 const int kTouchItemPadding = 8; | |
| 97 const int kTouchEdgeItemPadding = kTouchItemPadding; | |
| 98 | |
| 92 } // namespace | 99 } // namespace |
| 93 | 100 |
| 94 // static | 101 // static |
| 95 const int LocationBarView::kNormalHorizontalEdgeThickness = 2; | 102 const int LocationBarView::kNormalHorizontalEdgeThickness = 2; |
| 96 const int LocationBarView::kVerticalEdgeThickness = 3; | 103 const int LocationBarView::kVerticalEdgeThickness = 3; |
| 97 const int LocationBarView::kItemPadding = 3; | |
| 98 const int LocationBarView::kIconInternalPadding = 2; | 104 const int LocationBarView::kIconInternalPadding = 2; |
| 99 const int LocationBarView::kEdgeItemPadding = kItemPadding; | |
| 100 const int LocationBarView::kBubbleHorizontalPadding = 1; | 105 const int LocationBarView::kBubbleHorizontalPadding = 1; |
| 101 const char LocationBarView::kViewClassName[] = | 106 const char LocationBarView::kViewClassName[] = |
| 102 "browser/ui/views/location_bar/LocationBarView"; | 107 "browser/ui/views/location_bar/LocationBarView"; |
| 103 | 108 |
| 104 static const int kEVBubbleBackgroundImages[] = { | 109 static const int kEVBubbleBackgroundImages[] = { |
| 105 IDR_OMNIBOX_EV_BUBBLE_BACKGROUND_L, | 110 IDR_OMNIBOX_EV_BUBBLE_BACKGROUND_L, |
| 106 IDR_OMNIBOX_EV_BUBBLE_BACKGROUND_C, | 111 IDR_OMNIBOX_EV_BUBBLE_BACKGROUND_C, |
| 107 IDR_OMNIBOX_EV_BUBBLE_BACKGROUND_R, | 112 IDR_OMNIBOX_EV_BUBBLE_BACKGROUND_R, |
| 108 }; | 113 }; |
| 109 | 114 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 return color_utils::GetReadableColor(color, GetColor(security_level, | 301 return color_utils::GetReadableColor(color, GetColor(security_level, |
| 297 BACKGROUND)); | 302 BACKGROUND)); |
| 298 } | 303 } |
| 299 | 304 |
| 300 default: | 305 default: |
| 301 NOTREACHED(); | 306 NOTREACHED(); |
| 302 return GetColor(security_level, TEXT); | 307 return GetColor(security_level, TEXT); |
| 303 } | 308 } |
| 304 } | 309 } |
| 305 | 310 |
| 311 // static | |
| 312 int LocationBarView::GetItemPadding() { | |
| 313 if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) { | |
|
Peter Kasting
2012/05/11 23:01:41
Nit: No else after return; just do
return (ui::
Jói
2012/05/14 18:29:45
Done.
| |
| 314 return kTouchItemPadding; | |
| 315 } else { | |
| 316 return kDesktopItemPadding; | |
| 317 } | |
| 318 } | |
| 319 | |
| 320 // static | |
| 321 int LocationBarView::GetEdgeItemPadding() { | |
| 322 if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) { | |
| 323 return kTouchEdgeItemPadding; | |
| 324 } else { | |
| 325 return kDesktopItemPadding; | |
| 326 } | |
| 327 } | |
| 328 | |
| 306 // DropdownBarHostDelegate | 329 // DropdownBarHostDelegate |
| 307 void LocationBarView::SetFocusAndSelection(bool select_all) { | 330 void LocationBarView::SetFocusAndSelection(bool select_all) { |
| 308 FocusLocation(select_all); | 331 FocusLocation(select_all); |
| 309 } | 332 } |
| 310 | 333 |
| 311 void LocationBarView::SetAnimationOffset(int offset) { | 334 void LocationBarView::SetAnimationOffset(int offset) { |
| 312 animation_offset_ = offset; | 335 animation_offset_ = offset; |
| 313 } | 336 } |
| 314 | 337 |
| 315 void LocationBarView::Update(const WebContents* tab_for_state_restoring) { | 338 void LocationBarView::Update(const WebContents* tab_for_state_restoring) { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 506 int location_height = std::max(height() - (kVerticalEdgeThickness * 2), 0); | 529 int location_height = std::max(height() - (kVerticalEdgeThickness * 2), 0); |
| 507 | 530 |
| 508 // The edge stroke is 1 px thick. In popup mode, the edges are drawn by the | 531 // The edge stroke is 1 px thick. In popup mode, the edges are drawn by the |
| 509 // omnibox' parent, so there isn't any edge to account for at all. | 532 // omnibox' parent, so there isn't any edge to account for at all. |
| 510 const int kEdgeThickness = (mode_ == NORMAL) ? | 533 const int kEdgeThickness = (mode_ == NORMAL) ? |
| 511 kNormalHorizontalEdgeThickness : 0; | 534 kNormalHorizontalEdgeThickness : 0; |
| 512 // The edit has 1 px of horizontal whitespace inside it before the text. | 535 // The edit has 1 px of horizontal whitespace inside it before the text. |
| 513 const int kEditInternalSpace = 1; | 536 const int kEditInternalSpace = 1; |
| 514 // The space between an item and the edit is the normal item space, minus the | 537 // The space between an item and the edit is the normal item space, minus the |
| 515 // edit's built-in space (so the apparent space will be the same). | 538 // edit's built-in space (so the apparent space will be the same). |
| 516 const int kItemEditPadding = | 539 const int kItemEditPadding = GetItemPadding() - kEditInternalSpace; |
| 517 LocationBarView::kItemPadding - kEditInternalSpace; | 540 const int kEdgeEditPadding = GetEdgeItemPadding() - kEditInternalSpace; |
| 518 const int kEdgeEditPadding = | |
| 519 LocationBarView::kEdgeItemPadding - kEditInternalSpace; | |
| 520 const int kBubbleVerticalPadding = (mode_ == POPUP) ? | 541 const int kBubbleVerticalPadding = (mode_ == POPUP) ? |
| 521 -1 : kBubbleHorizontalPadding; | 542 -1 : kBubbleHorizontalPadding; |
| 522 | 543 |
| 523 // Start by reserving the padding at the right edge. | 544 // Start by reserving the padding at the right edge. |
| 524 int entry_width = width() - kEdgeThickness - kEdgeItemPadding; | 545 int entry_width = width() - kEdgeThickness - GetEdgeItemPadding(); |
| 525 | 546 |
| 526 // |location_icon_view_| is visible except when |ev_bubble_view_| or | 547 // |location_icon_view_| is visible except when |ev_bubble_view_| or |
| 527 // |selected_keyword_view_| are visible. | 548 // |selected_keyword_view_| are visible. |
| 528 int location_icon_width = 0; | 549 int location_icon_width = 0; |
| 529 int ev_bubble_width = 0; | 550 int ev_bubble_width = 0; |
| 530 location_icon_view_->SetVisible(false); | 551 location_icon_view_->SetVisible(false); |
| 531 ev_bubble_view_->SetVisible(false); | 552 ev_bubble_view_->SetVisible(false); |
| 532 const string16 keyword(location_entry_->model()->keyword()); | 553 const string16 keyword(location_entry_->model()->keyword()); |
| 533 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint()); | 554 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint()); |
| 534 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint; | 555 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint; |
| 535 if (show_selected_keyword) { | 556 if (show_selected_keyword) { |
| 536 // Assume the keyword might be hidden. | 557 // Assume the keyword might be hidden. |
| 537 entry_width -= (kEdgeThickness + kEdgeEditPadding); | 558 entry_width -= (kEdgeThickness + kEdgeEditPadding); |
| 538 } else if (model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { | 559 } else if (model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { |
| 539 ev_bubble_view_->SetVisible(true); | 560 ev_bubble_view_->SetVisible(true); |
| 540 ev_bubble_view_->SetLabel(model_->GetEVCertName()); | 561 ev_bubble_view_->SetLabel(model_->GetEVCertName()); |
| 541 ev_bubble_width = ev_bubble_view_->GetPreferredSize().width(); | 562 ev_bubble_width = ev_bubble_view_->GetPreferredSize().width(); |
| 542 // We'll adjust this width and take it out of |entry_width| below. | 563 // We'll adjust this width and take it out of |entry_width| below. |
| 543 } else { | 564 } else { |
| 544 location_icon_view_->SetVisible(true); | 565 location_icon_view_->SetVisible(true); |
| 545 location_icon_width = location_icon_view_->GetPreferredSize().width(); | 566 location_icon_width = location_icon_view_->GetPreferredSize().width(); |
| 546 entry_width -= (kEdgeThickness + kEdgeItemPadding + location_icon_width + | 567 entry_width -= (kEdgeThickness + GetEdgeItemPadding() + |
| 547 kItemEditPadding); | 568 location_icon_width + kItemEditPadding); |
| 548 } | 569 } |
| 549 | 570 |
| 550 if (star_view_ && star_view_->visible()) | 571 if (star_view_ && star_view_->visible()) |
| 551 entry_width -= star_view_->GetPreferredSize().width() + kItemPadding; | 572 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding(); |
| 552 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) | 573 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) |
| 553 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() + | 574 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() + |
| 554 kItemPadding; | 575 GetItemPadding(); |
| 555 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 576 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 556 i != page_action_views_.end(); ++i) { | 577 i != page_action_views_.end(); ++i) { |
| 557 if ((*i)->visible()) | 578 if ((*i)->visible()) |
| 558 entry_width -= ((*i)->GetPreferredSize().width() + kItemPadding); | 579 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); |
| 559 } | 580 } |
| 560 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 581 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
| 561 i != content_setting_views_.end(); ++i) { | 582 i != content_setting_views_.end(); ++i) { |
| 562 if ((*i)->visible()) | 583 if ((*i)->visible()) |
| 563 entry_width -= ((*i)->GetPreferredSize().width() + kItemPadding); | 584 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); |
| 564 } | 585 } |
| 565 // The gap between the edit and whatever is to its right is shortened. | 586 // The gap between the edit and whatever is to its right is shortened. |
| 566 entry_width += kEditInternalSpace; | 587 entry_width += kEditInternalSpace; |
| 567 | 588 |
| 568 // Size the EV bubble after taking star/ChromeToMobile/page actions/content | 589 // Size the EV bubble after taking star/ChromeToMobile/page actions/content |
| 569 // settings out of |entry_width| so we won't take too much space. | 590 // settings out of |entry_width| so we won't take too much space. |
| 570 if (ev_bubble_width) { | 591 if (ev_bubble_width) { |
| 571 // Try to elide the bubble to be no larger than half the total available | 592 // Try to elide the bubble to be no larger than half the total available |
| 572 // space, but never elide it any smaller than 150 px. | 593 // space, but never elide it any smaller than 150 px. |
| 573 static const int kMinElidedBubbleWidth = 150; | 594 static const int kMinElidedBubbleWidth = 150; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 605 *rb.GetBitmapNamed(IDR_OMNIBOX_SEARCH)); | 626 *rb.GetBitmapNamed(IDR_OMNIBOX_SEARCH)); |
| 606 selected_keyword_view_->set_is_extension_icon(false); | 627 selected_keyword_view_->set_is_extension_icon(false); |
| 607 } | 628 } |
| 608 } | 629 } |
| 609 } else if (show_keyword_hint) { | 630 } else if (show_keyword_hint) { |
| 610 if (keyword_hint_view_->keyword() != keyword) | 631 if (keyword_hint_view_->keyword() != keyword) |
| 611 keyword_hint_view_->SetKeyword(keyword); | 632 keyword_hint_view_->SetKeyword(keyword); |
| 612 } | 633 } |
| 613 | 634 |
| 614 // Lay out items to the right of the edit field. | 635 // Lay out items to the right of the edit field. |
| 615 int offset = width() - kEdgeThickness - kEdgeItemPadding; | 636 int offset = width() - kEdgeThickness - GetEdgeItemPadding(); |
| 616 if (star_view_ && star_view_->visible()) { | 637 if (star_view_ && star_view_->visible()) { |
| 617 int star_width = star_view_->GetPreferredSize().width(); | 638 int star_width = star_view_->GetPreferredSize().width(); |
| 618 offset -= star_width; | 639 offset -= star_width; |
| 619 star_view_->SetBounds(offset, location_y, star_width, location_height); | 640 star_view_->SetBounds(offset, location_y, star_width, location_height); |
| 620 offset -= kItemPadding; | 641 offset -= GetItemPadding(); |
| 621 } | 642 } |
| 622 | 643 |
| 623 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) { | 644 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) { |
| 624 int icon_width = chrome_to_mobile_view_->GetPreferredSize().width(); | 645 int icon_width = chrome_to_mobile_view_->GetPreferredSize().width(); |
| 625 offset -= icon_width; | 646 offset -= icon_width; |
| 626 chrome_to_mobile_view_->SetBounds(offset, location_y, | 647 chrome_to_mobile_view_->SetBounds(offset, location_y, |
| 627 icon_width, location_height); | 648 icon_width, location_height); |
| 628 offset -= kItemPadding; | 649 offset -= GetItemPadding(); |
| 629 } | 650 } |
| 630 | 651 |
| 631 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 652 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 632 i != page_action_views_.end(); ++i) { | 653 i != page_action_views_.end(); ++i) { |
| 633 if ((*i)->visible()) { | 654 if ((*i)->visible()) { |
| 634 int page_action_width = (*i)->GetPreferredSize().width(); | 655 int page_action_width = (*i)->GetPreferredSize().width(); |
| 635 offset -= page_action_width; | 656 offset -= page_action_width; |
| 636 (*i)->SetBounds(offset, location_y, page_action_width, location_height); | 657 (*i)->SetBounds(offset, location_y, page_action_width, location_height); |
| 637 offset -= kItemPadding; | 658 offset -= GetItemPadding(); |
| 638 } | 659 } |
| 639 } | 660 } |
| 640 // We use a reverse_iterator here because we're laying out the views from | 661 // We use a reverse_iterator here because we're laying out the views from |
| 641 // right to left but in the vector they're ordered left to right. | 662 // right to left but in the vector they're ordered left to right. |
| 642 for (ContentSettingViews::const_reverse_iterator | 663 for (ContentSettingViews::const_reverse_iterator |
| 643 i(content_setting_views_.rbegin()); i != content_setting_views_.rend(); | 664 i(content_setting_views_.rbegin()); i != content_setting_views_.rend(); |
| 644 ++i) { | 665 ++i) { |
| 645 if ((*i)->visible()) { | 666 if ((*i)->visible()) { |
| 646 int content_blocked_width = (*i)->GetPreferredSize().width(); | 667 int content_blocked_width = (*i)->GetPreferredSize().width(); |
| 647 offset -= content_blocked_width; | 668 offset -= content_blocked_width; |
| 648 (*i)->SetBounds(offset, location_y, content_blocked_width, | 669 (*i)->SetBounds(offset, location_y, content_blocked_width, |
| 649 location_height); | 670 location_height); |
| 650 offset -= kItemPadding; | 671 offset -= GetItemPadding(); |
| 651 } | 672 } |
| 652 } | 673 } |
| 653 | 674 |
| 654 // Now lay out items to the left of the edit field. | 675 // Now lay out items to the left of the edit field. |
| 655 if (location_icon_view_->visible()) { | 676 if (location_icon_view_->visible()) { |
| 656 location_icon_view_->SetBounds(kEdgeThickness + kEdgeItemPadding, | 677 location_icon_view_->SetBounds(kEdgeThickness + GetEdgeItemPadding(), |
| 657 location_y, location_icon_width, location_height); | 678 location_y, location_icon_width, location_height); |
| 658 offset = location_icon_view_->bounds().right() + kItemEditPadding; | 679 offset = location_icon_view_->bounds().right() + kItemEditPadding; |
| 659 } else if (ev_bubble_view_->visible()) { | 680 } else if (ev_bubble_view_->visible()) { |
| 660 ev_bubble_view_->SetBounds(kEdgeThickness + kBubbleHorizontalPadding, | 681 ev_bubble_view_->SetBounds(kEdgeThickness + kBubbleHorizontalPadding, |
| 661 location_y + kBubbleVerticalPadding, ev_bubble_width, | 682 location_y + kBubbleVerticalPadding, ev_bubble_width, |
| 662 ev_bubble_view_->GetPreferredSize().height()); | 683 ev_bubble_view_->GetPreferredSize().height()); |
| 663 offset = ev_bubble_view_->bounds().right() + kItemEditPadding; | 684 offset = ev_bubble_view_->bounds().right() + kItemEditPadding; |
| 664 } else { | 685 } else { |
| 665 offset = kEdgeThickness + | 686 offset = kEdgeThickness + |
| 666 (show_selected_keyword ? kBubbleHorizontalPadding : kEdgeEditPadding); | 687 (show_selected_keyword ? kBubbleHorizontalPadding : kEdgeEditPadding); |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1266 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && | 1287 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && |
| 1267 !suggested_text_view_->text().empty(); | 1288 !suggested_text_view_->text().empty(); |
| 1268 } | 1289 } |
| 1269 | 1290 |
| 1270 #if !defined(USE_AURA) | 1291 #if !defined(USE_AURA) |
| 1271 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { | 1292 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { |
| 1272 return static_cast<OmniboxViewWin*>(location_entry_.get()); | 1293 return static_cast<OmniboxViewWin*>(location_entry_.get()); |
| 1273 } | 1294 } |
| 1274 #endif | 1295 #endif |
| 1275 #endif | 1296 #endif |
| OLD | NEW |