location_icon_view.cc revision 0de6073388f4e2780db8536178b129cd8f6ab386
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. 4 5#include "chrome/browser/ui/views/location_bar/location_icon_view.h" 6 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" 12 13LocationIconView::LocationIconView(LocationBarView* location_bar) 14 : page_info_helper_(this, location_bar) { 15 SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON)); 16} 17 18LocationIconView::~LocationIconView() { 19} 20 21bool LocationIconView::OnMousePressed(const ui::MouseEvent& event) { 22 if (event.IsOnlyMiddleMouseButton() && 23 ui::Clipboard::IsSupportedClipboardType(ui::CLIPBOARD_TYPE_SELECTION)) { 24 base::string16 text; 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); 32 } 33 34 // Showing the bubble on mouse release is standard button behavior. 35 return true; 36} 37 38void LocationIconView::OnMouseReleased(const ui::MouseEvent& event) { 39 if (event.IsOnlyMiddleMouseButton()) 40 return; 41 OnClickOrTap(event); 42} 43 44bool LocationIconView::OnMouseDragged(const ui::MouseEvent& event) { 45 page_info_helper_.location_bar()->GetOmniboxView()->CloseOmniboxPopup(); 46 return false; 47} 48 49void LocationIconView::OnGestureEvent(ui::GestureEvent* event) { 50 if (event->type() != ui::ET_GESTURE_TAP) 51 return; 52 OnClickOrTap(*event); 53 event->SetHandled(); 54} 55 56void 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()) 63 return; 64 65 page_info_helper_.ProcessEvent(event); 66} 67 68void LocationIconView::ShowTooltip(bool show) { 69 SetTooltipText(show ? 70 l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON) : base::string16()); 71} 72