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.
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class UI_BASE_EXPORT TouchEditable : public ui::SimpleMenuModel::Delegate {
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(mohsen): Consider switching from local coordinates to screen
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // coordinates in this interface and see if it will simplify things.
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Select everything between start and end (points are in view's local
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // coordinate system). |start| is the logical start and |end| is the logical
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // end of selection. Visually, |start| may lie after |end|.
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SelectRect(const gfx::Point& start, const gfx::Point& end) = 0;
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Move the caret to |point|. |point| is in local coordinates.
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void MoveCaretTo(const gfx::Point& point) = 0;
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Gets the end points of the current selection. The end points p1 and p2 must
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // be the cursor rect for the start and end of selection (in local
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // coordinates):
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // ____________________________________
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // | textfield with |selected text|   |
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // ------------------------------------
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //                  ^p1           ^p2
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // p1 should be the logical start and p2 the logical end of selection. Hence,
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // visually, p1 could be to the right of p2 in the figure above.
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void GetSelectionEndPoints(gfx::Rect* p1, gfx::Rect* p2) = 0;
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Gets the bounds of the client view in its local coordinates.
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual gfx::Rect GetBounds() = 0;
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Gets the NativeView hosting the client.
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual gfx::NativeView GetNativeView() const = 0;
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Converts a point to/from screen coordinates from/to client view.
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void ConvertPointToScreen(gfx::Point* point) = 0;
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void ConvertPointFromScreen(gfx::Point* point) = 0;
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns true if the editable draws its own handles (hence, the
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // TouchSelectionController need not draw handles).
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool DrawsHandles() = 0;
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Tells the editable to open context menu.
567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual void OpenContextMenu(const gfx::Point& anchor) = 0;
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
58010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Tells the editable to end touch editing and destroy touch selection
59010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // controller it owns.
60010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual void DestroyTouchSelection() = 0;
61010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TouchEditable() {}
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This defines the callback interface for other code to be notified of changes
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// in the state of a TouchEditable.
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class UI_BASE_EXPORT TouchSelectionController {
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TouchSelectionController() {}
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Creates a TouchSelectionController. Caller owns the returned object.
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static TouchSelectionController* create(
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      TouchEditable* client_view);
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Notifies the controller that the selection has changed.
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SelectionChanged() = 0;
78c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
79c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns true if the user is currently dragging one of the handles.
80c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual bool IsHandleDragInProgress() = 0;
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Hides visible handles. According to the value of |quick|, handles might
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // fade out quickly or slowly.
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void HideHandles(bool quick) = 0;
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class UI_BASE_EXPORT TouchSelectionControllerFactory {
882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static void SetInstance(TouchSelectionControllerFactory* instance);
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual TouchSelectionController* create(TouchEditable* client_view) = 0;
922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TouchSelectionControllerFactory() {}
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace views
982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // UI_BASE_TOUCH_TOUCH_EDITING_CONTROLLER_H_
100