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