Home | History | Annotate | Download | only in input
      1 // Copyright 2014 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_TEXT_SELECTOR_H_
      6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_TEXT_SELECTOR_H_
      7 
      8 #include "base/gtest_prod_util.h"
      9 #include "base/macros.h"
     10 #include "base/time/time.h"
     11 #include "content/common/content_export.h"
     12 
     13 namespace ui {
     14 struct GestureEventData;
     15 class MotionEvent;
     16 }
     17 
     18 namespace content {
     19 class GestureTextSelectorTest;
     20 
     21 // Interface with which GestureTextSelector can select, unselect, show
     22 // selection handles, or long press.
     23 class CONTENT_EXPORT GestureTextSelectorClient {
     24  public:
     25   virtual ~GestureTextSelectorClient() {}
     26 
     27   virtual void ShowSelectionHandlesAutomatically() = 0;
     28   virtual void SelectRange(float x1, float y1, float x2, float y2) = 0;
     29   virtual void Unselect() = 0;
     30   virtual void LongPress(base::TimeTicks time, float x, float y) = 0;
     31 };
     32 
     33 // A class to handle gesture-based text selection, such as when clicking first
     34 // button on stylus input. It also generates a synthetic long press gesture on
     35 // tap so that a word can be selected or the contextual menu can be shown.
     36 class CONTENT_EXPORT GestureTextSelector {
     37  public:
     38   explicit GestureTextSelector(GestureTextSelectorClient* client);
     39   virtual ~GestureTextSelector();
     40 
     41   // This should be called after gesture detection but before associated
     42   // gestures are dispatched. Returns whether it will consume |event|.
     43   bool OnTouchEvent(const ui::MotionEvent& event);
     44 
     45   // Returns whether it will consume the event.
     46   bool OnGestureEvent(const ui::GestureEventData& gesture);
     47 
     48  private:
     49   friend class GestureTextSelectorTest;
     50   FRIEND_TEST_ALL_PREFIXES(GestureTextSelectorTest,
     51                            ShouldStartTextSelection);
     52 
     53   static bool ShouldStartTextSelection(const ui::MotionEvent& event);
     54 
     55   GestureTextSelectorClient* client_;
     56   bool text_selection_triggered_;
     57   float anchor_x_;
     58   float anchor_y_;
     59 
     60   DISALLOW_COPY_AND_ASSIGN(GestureTextSelector);
     61 };
     62 
     63 }  // namespace content
     64 
     65 #endif  // CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_TEXT_SELECTOR_H_
     66