location_bar_decoration_view.cc revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
1// Copyright 2013 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_bar_decoration_view.h"
6
7#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
8#include "ui/events/event.h"
9
10LocationBarDecorationView::LocationBarDecorationView()
11    : could_handle_click_(true) {
12  set_accessibility_focusable(true);
13  LocationBarView::InitTouchableLocationBarChildView(this);
14}
15
16LocationBarDecorationView::~LocationBarDecorationView() {}
17
18bool LocationBarDecorationView::OnMousePressed(const ui::MouseEvent& event) {
19  if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) {
20    // Do nothing until mouse is released.
21    could_handle_click_ = CanHandleClick();
22    return true;
23  }
24
25  return false;
26}
27
28void LocationBarDecorationView::OnMouseReleased(const ui::MouseEvent& event) {
29  if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location()) &&
30      could_handle_click_ && CanHandleClick()) {
31    OnClick();
32  }
33}
34
35bool LocationBarDecorationView::OnKeyPressed(const ui::KeyEvent& event) {
36  if (event.key_code() == ui::VKEY_SPACE ||
37      event.key_code() == ui::VKEY_RETURN) {
38    OnClick();
39    return true;
40  }
41
42  return false;
43}
44
45void LocationBarDecorationView::OnGestureEvent(ui::GestureEvent* event) {
46  if (event->type() == ui::ET_GESTURE_TAP) {
47    OnClick();
48    event->SetHandled();
49  }
50}
51
52bool LocationBarDecorationView::CanHandleClick() const {
53  return true;
54}
55