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
)) {
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();
39 void LocationIconView::OnMouseReleased(const ui::MouseEvent
& event
) {
40 if (event
.IsOnlyMiddleMouseButton())
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;
54 bool LocationIconView::OnMouseDragged(const ui::MouseEvent
& event
) {
55 page_info_helper_
.location_bar()->GetOmniboxView()->CloseOmniboxPopup();
59 void LocationIconView::OnGestureEvent(ui::GestureEvent
* event
) {
60 if (event
->type() != ui::ET_GESTURE_TAP
)
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())
72 page_info_helper_
.ProcessEvent(event
);
75 void LocationIconView::ShowTooltip(bool show
) {
77 l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON
) : base::string16());