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/search/search.h"
9 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
10 #include "grit/generated_resources.h"
11 #include "ui/base/l10n/l10n_util.h"
13 LocationIconView::LocationIconView(LocationBarView* location_bar)
14 : page_info_helper_(this, location_bar) {
15 SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON));
18 LocationIconView::~LocationIconView() {
21 bool LocationIconView::OnMousePressed(const ui::MouseEvent& event) {
22 if (event.IsOnlyMiddleMouseButton() &&
23 ui::Clipboard::IsSupportedClipboardType(ui::CLIPBOARD_TYPE_SELECTION)) {
25 ui::Clipboard::GetForCurrentThread()->ReadText(
26 ui::CLIPBOARD_TYPE_SELECTION, &text);
27 text = OmniboxView::SanitizeTextForPaste(text);
28 OmniboxEditModel* model =
29 page_info_helper_.location_bar()->GetOmniboxView()->model();
30 if (model->CanPasteAndGo(text))
31 model->PasteAndGo(text);
34 // Showing the bubble on mouse release is standard button behavior.
38 void LocationIconView::OnMouseReleased(const ui::MouseEvent& event) {
39 if (event.IsOnlyMiddleMouseButton())
44 bool LocationIconView::OnMouseDragged(const ui::MouseEvent& event) {
45 page_info_helper_.location_bar()->GetOmniboxView()->CloseOmniboxPopup();
49 void LocationIconView::OnGestureEvent(ui::GestureEvent* event) {
50 if (event->type() != ui::ET_GESTURE_TAP)
56 void LocationIconView::OnClickOrTap(const ui::LocatedEvent& event) {
57 // Do not show page info if the user has been editing the location bar or the
58 // location bar is at the NTP. Also skip showing the page info if the
59 // toolbar-based origin chip is being shown because it is responsible for
60 // showing the page info instead.
61 if (page_info_helper_.location_bar()->GetOmniboxView()->IsEditingOrEmpty() ||
62 chrome::ShouldDisplayOriginChip())
65 page_info_helper_.ProcessEvent(event);
68 void LocationIconView::ShowTooltip(bool show) {
70 l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON) : base::string16());