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 "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" 12 13LocationIconView::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)); 17} 18 19LocationIconView::~LocationIconView() { 20} 21 22bool 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); 33 } 34 35 suppress_mouse_released_action_ = WebsiteSettingsPopupView::IsPopupShowing(); 36 return true; 37} 38 39void LocationIconView::OnMouseReleased(const ui::MouseEvent& event) { 40 if (event.IsOnlyMiddleMouseButton()) 41 return; 42 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; 49 } 50 51 OnClickOrTap(event); 52} 53 54bool LocationIconView::OnMouseDragged(const ui::MouseEvent& event) { 55 page_info_helper_.location_bar()->GetOmniboxView()->CloseOmniboxPopup(); 56 return false; 57} 58 59void LocationIconView::OnGestureEvent(ui::GestureEvent* event) { 60 if (event->type() != ui::ET_GESTURE_TAP) 61 return; 62 OnClickOrTap(*event); 63 event->SetHandled(); 64} 65 66void 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; 71 72 page_info_helper_.ProcessEvent(event); 73} 74 75void LocationIconView::ShowTooltip(bool show) { 76 SetTooltipText(show ? 77 l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON) : base::string16()); 78} 79