location_icon_view.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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  LocationBarView::InitTouchableLocationBarChildView(this);
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()->omnibox_view()->model();
31    if (model->CanPasteAndGo(text))
32      model->PasteAndGo(text);
33  }
34
35  // Showing the bubble on mouse release is standard button behavior.
36  return true;
37}
38
39void LocationIconView::OnMouseReleased(const ui::MouseEvent& event) {
40  if (!event.IsOnlyMiddleMouseButton() &&
41      !chrome::ShouldDisplayOriginChip() &&
42      !chrome::ShouldDisplayOriginChipV2())
43    page_info_helper_.ProcessEvent(event);
44}
45
46void LocationIconView::OnGestureEvent(ui::GestureEvent* event) {
47  if (!chrome::ShouldDisplayOriginChip() &&
48      !chrome::ShouldDisplayOriginChipV2() &&
49      (event->type() == ui::ET_GESTURE_TAP)) {
50    page_info_helper_.ProcessEvent(*event);
51    event->SetHandled();
52  }
53}
54
55void LocationIconView::ShowTooltip(bool show) {
56  SetTooltipText(show ?
57      l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON) : base::string16());
58}
59