[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / location_bar / location_icon_view.cc
blob7a3b17978d7db5c34c7ab815a370ff46e1df679f
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/ui/views/location_bar/location_bar_view.h"
9 #include "grit/generated_resources.h"
10 #include "ui/base/l10n/l10n_util.h"
12 LocationIconView::LocationIconView(LocationBarView* location_bar)
13 : page_info_helper_(this, location_bar) {
14 SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON));
17 LocationIconView::~LocationIconView() {
20 bool 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);
33 // Showing the bubble on mouse release is standard button behavior.
34 return true;
37 void LocationIconView::OnMouseReleased(const ui::MouseEvent& event) {
38 if (event.IsOnlyMiddleMouseButton())
39 return;
40 OnClickOrTap(event);
43 bool LocationIconView::OnMouseDragged(const ui::MouseEvent& event) {
44 page_info_helper_.location_bar()->GetOmniboxView()->CloseOmniboxPopup();
45 return false;
48 void LocationIconView::OnGestureEvent(ui::GestureEvent* event) {
49 if (event->type() != ui::ET_GESTURE_TAP)
50 return;
51 OnClickOrTap(*event);
52 event->SetHandled();
55 void 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;
61 page_info_helper_.ProcessEvent(event);
64 void LocationIconView::ShowTooltip(bool show) {
65 SetTooltipText(show ?
66 l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON) : base::string16());