Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / views / location_bar / location_icon_view.cc
blobb40af8d5d64cc1d8b6e1757cddc3119e9c9cbb22
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
9 #include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h"
10 #include "chrome/grit/generated_resources.h"
11 #include "ui/base/l10n/l10n_util.h"
13 LocationIconView::LocationIconView(LocationBarView* location_bar)
14 : suppress_mouse_released_action_(false),
15 page_info_helper_(this, location_bar) {
16 SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON));
19 LocationIconView::~LocationIconView() {
22 bool LocationIconView::OnMousePressed(const ui::MouseEvent& event) {
23 if (event.IsOnlyMiddleMouseButton() &&
24 ui::Clipboard::IsSupportedClipboardType(ui::CLIPBOARD_TYPE_SELECTION)) {
25 base::string16 text;
26 ui::Clipboard::GetForCurrentThread()->ReadText(
27 ui::CLIPBOARD_TYPE_SELECTION, &text);
28 text = OmniboxView::SanitizeTextForPaste(text);
29 OmniboxEditModel* model =
30 page_info_helper_.location_bar()->GetOmniboxView()->model();
31 if (model->CanPasteAndGo(text))
32 model->PasteAndGo(text);
35 suppress_mouse_released_action_ = WebsiteSettingsPopupView::IsPopupShowing();
36 return true;
39 void LocationIconView::OnMouseReleased(const ui::MouseEvent& event) {
40 if (event.IsOnlyMiddleMouseButton())
41 return;
43 // If this is the second click on this view then the bubble was showing on
44 // the mouse pressed event and is hidden now. Prevent the bubble from
45 // reshowing by doing nothing here.
46 if (suppress_mouse_released_action_) {
47 suppress_mouse_released_action_ = false;
48 return;
51 OnClickOrTap(event);
54 bool LocationIconView::OnMouseDragged(const ui::MouseEvent& event) {
55 page_info_helper_.location_bar()->GetOmniboxView()->CloseOmniboxPopup();
56 return false;
59 void LocationIconView::OnGestureEvent(ui::GestureEvent* event) {
60 if (event->type() != ui::ET_GESTURE_TAP)
61 return;
62 OnClickOrTap(*event);
63 event->SetHandled();
66 void LocationIconView::OnClickOrTap(const ui::LocatedEvent& event) {
67 // Do not show page info if the user has been editing the location bar or the
68 // location bar is at the NTP.
69 if (page_info_helper_.location_bar()->GetOmniboxView()->IsEditingOrEmpty())
70 return;
72 page_info_helper_.ProcessEvent(event);
75 void LocationIconView::ShowTooltip(bool show) {
76 SetTooltipText(show ?
77 l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON) : base::string16());