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