touch_editing_controller.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef UI_BASE_TOUCH_TOUCH_EDITING_CONTROLLER_H_
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define UI_BASE_TOUCH_TOUCH_EDITING_CONTROLLER_H_
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/models/simple_menu_model.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/point.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/rect.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace ui {
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// An interface implemented by widget that has text that can be selected/edited
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// using touch.
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class UI_EXPORT TouchEditable : public ui::SimpleMenuModel::Delegate {
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Select everything between start and end (points are in view's local
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // coordinate system). |start| is the logical start and |end| is the logical
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // end of selection. Visually, |start| may lie after |end|.
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SelectRect(const gfx::Point& start, const gfx::Point& end) = 0;
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Move the caret to |point|. |point| is in local coordinates.
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void MoveCaretTo(const gfx::Point& point) = 0;
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Gets the end points of the current selection. The end points p1 and p2 must
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // be the cursor rect for the start and end of selection:
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // ____________________________________
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // | textfield with |selected text|   |
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // ------------------------------------
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //                  ^p1           ^p2
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // p1 should be the logical start and p2 the logical end of selection. Hence,
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // visually, p1 could be to the right of p2 in the figure above.
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void GetSelectionEndPoints(gfx::Rect* p1, gfx::Rect* p2) = 0;
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Gets the bounds of the client view in parent's coordinates.
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual gfx::Rect GetBounds() = 0;
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Gets the NativeView hosting the client.
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual gfx::NativeView GetNativeView() = 0;
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Converts a point to/from screen coordinates from/to client view.
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void ConvertPointToScreen(gfx::Point* point) = 0;
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void ConvertPointFromScreen(gfx::Point* point) = 0;
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns true if the editable draws its own handles (hence, the
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // TouchSelectionController need not draw handles).
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool DrawsHandles() = 0;
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Tells the editable to open context menu.
527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual void OpenContextMenu(const gfx::Point& anchor) = 0;
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TouchEditable() {}
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This defines the callback interface for other code to be notified of changes
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// in the state of a TouchEditable.
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class UI_EXPORT TouchSelectionController {
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TouchSelectionController() {}
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Creates a TouchSelectionController. Caller owns the returned object.
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static TouchSelectionController* create(
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      TouchEditable* client_view);
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Notifies the controller that the selection has changed.
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SelectionChanged() = 0;
70c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
71c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns true if the user is currently dragging one of the handles.
72c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual bool IsHandleDragInProgress() = 0;
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class UI_EXPORT TouchSelectionControllerFactory {
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static void SetInstance(TouchSelectionControllerFactory* instance);
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual TouchSelectionController* create(TouchEditable* client_view) = 0;
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TouchSelectionControllerFactory() {}
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace views
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // UI_BASE_TOUCH_TOUCH_EDITING_CONTROLLER_H_
88