| 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 return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? |
| 314 kTouchItemPadding : kDesktopItemPadding; |
| 315 } |
| 316 |
| 317 // static |
| 318 int LocationBarView::GetEdgeItemPadding() { |
| 319 return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? |
| 320 kTouchEdgeItemPadding : kDesktopEdgeItemPadding; |
| 321 } |
| 322 |
| 306 // DropdownBarHostDelegate | 323 // DropdownBarHostDelegate |
| 307 void LocationBarView::SetFocusAndSelection(bool select_all) { | 324 void LocationBarView::SetFocusAndSelection(bool select_all) { |
| 308 FocusLocation(select_all); | 325 FocusLocation(select_all); |
| 309 } | 326 } |
| 310 | 327 |
| 311 void LocationBarView::SetAnimationOffset(int offset) { | 328 void LocationBarView::SetAnimationOffset(int offset) { |
| 312 animation_offset_ = offset; | 329 animation_offset_ = offset; |
| 313 } | 330 } |
| 314 | 331 |
| 315 void LocationBarView::Update(const WebContents* tab_for_state_restoring) { | 332 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); | 523 int location_height = std::max(height() - (kVerticalEdgeThickness * 2), 0); |
| 507 | 524 |
| 508 // The edge stroke is 1 px thick. In popup mode, the edges are drawn by the | 525 // 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. | 526 // omnibox' parent, so there isn't any edge to account for at all. |
| 510 const int kEdgeThickness = (mode_ == NORMAL) ? | 527 const int kEdgeThickness = (mode_ == NORMAL) ? |
| 511 kNormalHorizontalEdgeThickness : 0; | 528 kNormalHorizontalEdgeThickness : 0; |
| 512 // The edit has 1 px of horizontal whitespace inside it before the text. | 529 // The edit has 1 px of horizontal whitespace inside it before the text. |
| 513 const int kEditInternalSpace = 1; | 530 const int kEditInternalSpace = 1; |
| 514 // The space between an item and the edit is the normal item space, minus the | 531 // 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). | 532 // edit's built-in space (so the apparent space will be the same). |
| 516 const int kItemEditPadding = | 533 const int kItemEditPadding = GetItemPadding() - kEditInternalSpace; |
| 517 LocationBarView::kItemPadding - kEditInternalSpace; | 534 const int kEdgeEditPadding = GetEdgeItemPadding() - kEditInternalSpace; |
| 518 const int kEdgeEditPadding = | |
| 519 LocationBarView::kEdgeItemPadding - kEditInternalSpace; | |
| 520 const int kBubbleVerticalPadding = (mode_ == POPUP) ? | 535 const int kBubbleVerticalPadding = (mode_ == POPUP) ? |
| 521 -1 : kBubbleHorizontalPadding; | 536 -1 : kBubbleHorizontalPadding; |
| 522 | 537 |
| 523 // Start by reserving the padding at the right edge. | 538 // Start by reserving the padding at the right edge. |
| 524 int entry_width = width() - kEdgeThickness - kEdgeItemPadding; | 539 int entry_width = width() - kEdgeThickness - GetEdgeItemPadding(); |
| 525 | 540 |
| 526 // |location_icon_view_| is visible except when |ev_bubble_view_| or | 541 // |location_icon_view_| is visible except when |ev_bubble_view_| or |
| 527 // |selected_keyword_view_| are visible. | 542 // |selected_keyword_view_| are visible. |
| 528 int location_icon_width = 0; | 543 int location_icon_width = 0; |
| 529 int ev_bubble_width = 0; | 544 int ev_bubble_width = 0; |
| 530 location_icon_view_->SetVisible(false); | 545 location_icon_view_->SetVisible(false); |
| 531 ev_bubble_view_->SetVisible(false); | 546 ev_bubble_view_->SetVisible(false); |
| 532 const string16 keyword(location_entry_->model()->keyword()); | 547 const string16 keyword(location_entry_->model()->keyword()); |
| 533 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint()); | 548 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint()); |
| 534 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint; | 549 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint; |
| 535 if (show_selected_keyword) { | 550 if (show_selected_keyword) { |
| 536 // Assume the keyword might be hidden. | 551 // Assume the keyword might be hidden. |
| 537 entry_width -= (kEdgeThickness + kEdgeEditPadding); | 552 entry_width -= (kEdgeThickness + kEdgeEditPadding); |
| 538 } else if (model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { | 553 } else if (model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { |
| 539 ev_bubble_view_->SetVisible(true); | 554 ev_bubble_view_->SetVisible(true); |
| 540 ev_bubble_view_->SetLabel(model_->GetEVCertName()); | 555 ev_bubble_view_->SetLabel(model_->GetEVCertName()); |
| 541 ev_bubble_width = ev_bubble_view_->GetPreferredSize().width(); | 556 ev_bubble_width = ev_bubble_view_->GetPreferredSize().width(); |
| 542 // We'll adjust this width and take it out of |entry_width| below. | 557 // We'll adjust this width and take it out of |entry_width| below. |
| 543 } else { | 558 } else { |
| 544 location_icon_view_->SetVisible(true); | 559 location_icon_view_->SetVisible(true); |
| 545 location_icon_width = location_icon_view_->GetPreferredSize().width(); | 560 location_icon_width = location_icon_view_->GetPreferredSize().width(); |
| 546 entry_width -= (kEdgeThickness + kEdgeItemPadding + location_icon_width + | 561 entry_width -= (kEdgeThickness + GetEdgeItemPadding() + |
| 547 kItemEditPadding); | 562 location_icon_width + kItemEditPadding); |
| 548 } | 563 } |
| 549 | 564 |
| 550 if (star_view_ && star_view_->visible()) | 565 if (star_view_ && star_view_->visible()) |
| 551 entry_width -= star_view_->GetPreferredSize().width() + kItemPadding; | 566 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding(); |
| 552 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) | 567 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) |
| 553 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() + | 568 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() + |
| 554 kItemPadding; | 569 GetItemPadding(); |
| 555 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 570 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 556 i != page_action_views_.end(); ++i) { | 571 i != page_action_views_.end(); ++i) { |
| 557 if ((*i)->visible()) | 572 if ((*i)->visible()) |
| 558 entry_width -= ((*i)->GetPreferredSize().width() + kItemPadding); | 573 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); |
| 559 } | 574 } |
| 560 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 575 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
| 561 i != content_setting_views_.end(); ++i) { | 576 i != content_setting_views_.end(); ++i) { |
| 562 if ((*i)->visible()) | 577 if ((*i)->visible()) |
| 563 entry_width -= ((*i)->GetPreferredSize().width() + kItemPadding); | 578 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); |
| 564 } | 579 } |
| 565 // The gap between the edit and whatever is to its right is shortened. | 580 // The gap between the edit and whatever is to its right is shortened. |
| 566 entry_width += kEditInternalSpace; | 581 entry_width += kEditInternalSpace; |
| 567 | 582 |
| 568 // Size the EV bubble after taking star/ChromeToMobile/page actions/content | 583 // 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. | 584 // settings out of |entry_width| so we won't take too much space. |
| 570 if (ev_bubble_width) { | 585 if (ev_bubble_width) { |
| 571 // Try to elide the bubble to be no larger than half the total available | 586 // 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. | 587 // space, but never elide it any smaller than 150 px. |
| 573 static const int kMinElidedBubbleWidth = 150; | 588 static const int kMinElidedBubbleWidth = 150; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 *rb.GetBitmapNamed(IDR_OMNIBOX_SEARCH)); | 620 *rb.GetBitmapNamed(IDR_OMNIBOX_SEARCH)); |
| 606 selected_keyword_view_->set_is_extension_icon(false); | 621 selected_keyword_view_->set_is_extension_icon(false); |
| 607 } | 622 } |
| 608 } | 623 } |
| 609 } else if (show_keyword_hint) { | 624 } else if (show_keyword_hint) { |
| 610 if (keyword_hint_view_->keyword() != keyword) | 625 if (keyword_hint_view_->keyword() != keyword) |
| 611 keyword_hint_view_->SetKeyword(keyword); | 626 keyword_hint_view_->SetKeyword(keyword); |
| 612 } | 627 } |
| 613 | 628 |
| 614 // Lay out items to the right of the edit field. | 629 // Lay out items to the right of the edit field. |
| 615 int offset = width() - kEdgeThickness - kEdgeItemPadding; | 630 int offset = width() - kEdgeThickness - GetEdgeItemPadding(); |
| 616 if (star_view_ && star_view_->visible()) { | 631 if (star_view_ && star_view_->visible()) { |
| 617 int star_width = star_view_->GetPreferredSize().width(); | 632 int star_width = star_view_->GetPreferredSize().width(); |
| 618 offset -= star_width; | 633 offset -= star_width; |
| 619 star_view_->SetBounds(offset, location_y, star_width, location_height); | 634 star_view_->SetBounds(offset, location_y, star_width, location_height); |
| 620 offset -= kItemPadding; | 635 offset -= GetItemPadding(); |
| 621 } | 636 } |
| 622 | 637 |
| 623 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) { | 638 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) { |
| 624 int icon_width = chrome_to_mobile_view_->GetPreferredSize().width(); | 639 int icon_width = chrome_to_mobile_view_->GetPreferredSize().width(); |
| 625 offset -= icon_width; | 640 offset -= icon_width; |
| 626 chrome_to_mobile_view_->SetBounds(offset, location_y, | 641 chrome_to_mobile_view_->SetBounds(offset, location_y, |
| 627 icon_width, location_height); | 642 icon_width, location_height); |
| 628 offset -= kItemPadding; | 643 offset -= GetItemPadding(); |
| 629 } | 644 } |
| 630 | 645 |
| 631 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 646 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 632 i != page_action_views_.end(); ++i) { | 647 i != page_action_views_.end(); ++i) { |
| 633 if ((*i)->visible()) { | 648 if ((*i)->visible()) { |
| 634 int page_action_width = (*i)->GetPreferredSize().width(); | 649 int page_action_width = (*i)->GetPreferredSize().width(); |
| 635 offset -= page_action_width; | 650 offset -= page_action_width; |
| 636 (*i)->SetBounds(offset, location_y, page_action_width, location_height); | 651 (*i)->SetBounds(offset, location_y, page_action_width, location_height); |
| 637 offset -= kItemPadding; | 652 offset -= GetItemPadding(); |
| 638 } | 653 } |
| 639 } | 654 } |
| 640 // We use a reverse_iterator here because we're laying out the views from | 655 // 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. | 656 // right to left but in the vector they're ordered left to right. |
| 642 for (ContentSettingViews::const_reverse_iterator | 657 for (ContentSettingViews::const_reverse_iterator |
| 643 i(content_setting_views_.rbegin()); i != content_setting_views_.rend(); | 658 i(content_setting_views_.rbegin()); i != content_setting_views_.rend(); |
| 644 ++i) { | 659 ++i) { |
| 645 if ((*i)->visible()) { | 660 if ((*i)->visible()) { |
| 646 int content_blocked_width = (*i)->GetPreferredSize().width(); | 661 int content_blocked_width = (*i)->GetPreferredSize().width(); |
| 647 offset -= content_blocked_width; | 662 offset -= content_blocked_width; |
| 648 (*i)->SetBounds(offset, location_y, content_blocked_width, | 663 (*i)->SetBounds(offset, location_y, content_blocked_width, |
| 649 location_height); | 664 location_height); |
| 650 offset -= kItemPadding; | 665 offset -= GetItemPadding(); |
| 651 } | 666 } |
| 652 } | 667 } |
| 653 | 668 |
| 654 // Now lay out items to the left of the edit field. | 669 // Now lay out items to the left of the edit field. |
| 655 if (location_icon_view_->visible()) { | 670 if (location_icon_view_->visible()) { |
| 656 location_icon_view_->SetBounds(kEdgeThickness + kEdgeItemPadding, | 671 location_icon_view_->SetBounds(kEdgeThickness + GetEdgeItemPadding(), |
| 657 location_y, location_icon_width, location_height); | 672 location_y, location_icon_width, location_height); |
| 658 offset = location_icon_view_->bounds().right() + kItemEditPadding; | 673 offset = location_icon_view_->bounds().right() + kItemEditPadding; |
| 659 } else if (ev_bubble_view_->visible()) { | 674 } else if (ev_bubble_view_->visible()) { |
| 660 ev_bubble_view_->SetBounds(kEdgeThickness + kBubbleHorizontalPadding, | 675 ev_bubble_view_->SetBounds(kEdgeThickness + kBubbleHorizontalPadding, |
| 661 location_y + kBubbleVerticalPadding, ev_bubble_width, | 676 location_y + kBubbleVerticalPadding, ev_bubble_width, |
| 662 ev_bubble_view_->GetPreferredSize().height()); | 677 ev_bubble_view_->GetPreferredSize().height()); |
| 663 offset = ev_bubble_view_->bounds().right() + kItemEditPadding; | 678 offset = ev_bubble_view_->bounds().right() + kItemEditPadding; |
| 664 } else { | 679 } else { |
| 665 offset = kEdgeThickness + | 680 offset = kEdgeThickness + |
| 666 (show_selected_keyword ? kBubbleHorizontalPadding : kEdgeEditPadding); | 681 (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() && | 1281 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && |
| 1267 !suggested_text_view_->text().empty(); | 1282 !suggested_text_view_->text().empty(); |
| 1268 } | 1283 } |
| 1269 | 1284 |
| 1270 #if !defined(USE_AURA) | 1285 #if !defined(USE_AURA) |
| 1271 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { | 1286 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { |
| 1272 return static_cast<OmniboxViewWin*>(location_entry_.get()); | 1287 return static_cast<OmniboxViewWin*>(location_entry_.get()); |
| 1273 } | 1288 } |
| 1274 #endif | 1289 #endif |
| 1275 #endif | 1290 #endif |
| OLD | NEW |