location_icon_view.cc revision cedac228d2dd51db4b79ea1e72c7f249408ee061
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/ui/views/location_bar/location_bar_view.h" 9#include "grit/generated_resources.h" 10#include "ui/base/l10n/l10n_util.h" 11 12LocationIconView::LocationIconView(LocationBarView* location_bar) 13 : page_info_helper_(this, location_bar) { 14 SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON)); 15} 16 17LocationIconView::~LocationIconView() { 18} 19 20bool LocationIconView::OnMousePressed(const ui::MouseEvent& event) { 21 if (event.IsOnlyMiddleMouseButton() && 22 ui::Clipboard::IsSupportedClipboardType(ui::CLIPBOARD_TYPE_SELECTION)) { 23 base::string16 text; 24 ui::Clipboard::GetForCurrentThread()->ReadText( 25 ui::CLIPBOARD_TYPE_SELECTION, &text); 26 text = OmniboxView::SanitizeTextForPaste(text); 27 OmniboxEditModel* model = 28 page_info_helper_.location_bar()->GetOmniboxView()->model(); 29 if (model->CanPasteAndGo(text)) 30 model->PasteAndGo(text); 31 } 32 33 // Showing the bubble on mouse release is standard button behavior. 34 return true; 35} 36 37void LocationIconView::OnMouseReleased(const ui::MouseEvent& event) { 38 if (event.IsOnlyMiddleMouseButton()) 39 return; 40 OnClickOrTap(event); 41} 42 43bool LocationIconView::OnMouseDragged(const ui::MouseEvent& event) { 44 page_info_helper_.location_bar()->GetOmniboxView()->CloseOmniboxPopup(); 45 return false; 46} 47 48void LocationIconView::OnGestureEvent(ui::GestureEvent* event) { 49 if (event->type() != ui::ET_GESTURE_TAP) 50 return; 51 OnClickOrTap(*event); 52 event->SetHandled(); 53} 54 55void LocationIconView::OnClickOrTap(const ui::LocatedEvent& event) { 56 // Do not show page info if the user has been editing the location bar or the 57 // location bar is at the NTP. 58 if (page_info_helper_.location_bar()->GetOmniboxView()->IsEditingOrEmpty()) 59 return; 60 61 page_info_helper_.ProcessEvent(event); 62} 63 64void LocationIconView::ShowTooltip(bool show) { 65 SetTooltipText(show ? 66 l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON) : base::string16()); 67} 68