Home | History | Annotate | Download | only in touch
      1 // Copyright (c) 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 #ifndef UI_BASE_TOUCH_TOUCH_EDITING_CONTROLLER_H_
      6 #define UI_BASE_TOUCH_TOUCH_EDITING_CONTROLLER_H_
      7 
      8 #include "ui/base/models/simple_menu_model.h"
      9 #include "ui/gfx/point.h"
     10 #include "ui/gfx/rect.h"
     11 
     12 namespace ui {
     13 
     14 // An interface implemented by widget that has text that can be selected/edited
     15 // using touch.
     16 class UI_EXPORT TouchEditable : public ui::SimpleMenuModel::Delegate {
     17  public:
     18   // Select everything between start and end (points are in view's local
     19   // coordinate system). |start| is the logical start and |end| is the logical
     20   // end of selection. Visually, |start| may lie after |end|.
     21   virtual void SelectRect(const gfx::Point& start, const gfx::Point& end) = 0;
     22 
     23   // Move the caret to |point|. |point| is in local coordinates.
     24   virtual void MoveCaretTo(const gfx::Point& point) = 0;
     25 
     26   // Gets the end points of the current selection. The end points p1 and p2 must
     27   // be the cursor rect for the start and end of selection:
     28   // ____________________________________
     29   // | textfield with |selected text|   |
     30   // ------------------------------------
     31   //                  ^p1           ^p2
     32   //
     33   // p1 should be the logical start and p2 the logical end of selection. Hence,
     34   // visually, p1 could be to the right of p2 in the figure above.
     35   virtual void GetSelectionEndPoints(gfx::Rect* p1, gfx::Rect* p2) = 0;
     36 
     37   // Gets the bounds of the client view in parent's coordinates.
     38   virtual gfx::Rect GetBounds() = 0;
     39 
     40   // Gets the NativeView hosting the client.
     41   virtual gfx::NativeView GetNativeView() = 0;
     42 
     43   // Converts a point to/from screen coordinates from/to client view.
     44   virtual void ConvertPointToScreen(gfx::Point* point) = 0;
     45   virtual void ConvertPointFromScreen(gfx::Point* point) = 0;
     46 
     47   // Returns true if the editable draws its own handles (hence, the
     48   // TouchSelectionController need not draw handles).
     49   virtual bool DrawsHandles() = 0;
     50 
     51   // Tells the editable to open context menu.
     52   virtual void OpenContextMenu(const gfx::Point& anchor) = 0;
     53 
     54  protected:
     55   virtual ~TouchEditable() {}
     56 };
     57 
     58 // This defines the callback interface for other code to be notified of changes
     59 // in the state of a TouchEditable.
     60 class UI_EXPORT TouchSelectionController {
     61  public:
     62   virtual ~TouchSelectionController() {}
     63 
     64   // Creates a TouchSelectionController. Caller owns the returned object.
     65   static TouchSelectionController* create(
     66       TouchEditable* client_view);
     67 
     68   // Notifies the controller that the selection has changed.
     69   virtual void SelectionChanged() = 0;
     70 
     71   // Returns true if the user is currently dragging one of the handles.
     72   virtual bool IsHandleDragInProgress() = 0;
     73 };
     74 
     75 class UI_EXPORT TouchSelectionControllerFactory {
     76  public:
     77   static void SetInstance(TouchSelectionControllerFactory* instance);
     78 
     79   virtual TouchSelectionController* create(TouchEditable* client_view) = 0;
     80 
     81  protected:
     82   virtual ~TouchSelectionControllerFactory() {}
     83 };
     84 
     85 }  // namespace views
     86 
     87 #endif  // UI_BASE_TOUCH_TOUCH_EDITING_CONTROLLER_H_
     88