15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/views/location_bar/location_icon_view.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 8ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "chrome/browser/ui/views/location_bar/location_bar_view.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "grit/generated_resources.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)LocationIconView::LocationIconView(LocationBarView* location_bar) 13c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) : page_info_helper_(this, location_bar) { 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON)); 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)LocationIconView::~LocationIconView() { 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool LocationIconView::OnMousePressed(const ui::MouseEvent& event) { 21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (event.IsOnlyMiddleMouseButton() && 22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::Clipboard::IsSupportedClipboardType(ui::CLIPBOARD_TYPE_SELECTION)) { 23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::string16 text; 24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::Clipboard::GetForCurrentThread()->ReadText( 25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::CLIPBOARD_TYPE_SELECTION, &text); 26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) text = OmniboxView::SanitizeTextForPaste(text); 27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) OmniboxEditModel* model = 280de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) page_info_helper_.location_bar()->GetOmniboxView()->model(); 29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (model->CanPasteAndGo(text)) 30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) model->PasteAndGo(text); 31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Showing the bubble on mouse release is standard button behavior. 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void LocationIconView::OnMouseReleased(const ui::MouseEvent& event) { 38effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (event.IsOnlyMiddleMouseButton()) 39effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return; 40effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch OnClickOrTap(event); 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 430de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)bool LocationIconView::OnMouseDragged(const ui::MouseEvent& event) { 440de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) page_info_helper_.location_bar()->GetOmniboxView()->CloseOmniboxPopup(); 450de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) return false; 460de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)} 470de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void LocationIconView::OnGestureEvent(ui::GestureEvent* event) { 49effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (event->type() != ui::ET_GESTURE_TAP) 50effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return; 51effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch OnClickOrTap(*event); 52effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch event->SetHandled(); 53effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 54effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 55effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid LocationIconView::OnClickOrTap(const ui::LocatedEvent& event) { 56effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Do not show page info if the user has been editing the location bar or the 57cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // location bar is at the NTP. 58cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (page_info_helper_.location_bar()->GetOmniboxView()->IsEditingOrEmpty()) 59effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return; 60effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 61effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch page_info_helper_.ProcessEvent(event); 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void LocationIconView::ShowTooltip(bool show) { 65ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch SetTooltipText(show ? 66ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON) : base::string16()); 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 68