summaryrefslogtreecommitdiffstats
path: root/views/touchui/touch_selection_controller.h
blob: 58f6f91bf7974e81ce79236b4368588b3907118b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef VIEWS_TOUCHUI_TOUCH_SELECTION_CONTROLLER_H_
#define VIEWS_TOUCHUI_TOUCH_SELECTION_CONTROLLER_H_
#pragma once

#include "ui/base/models/simple_menu_model.h"
#include "ui/gfx/point.h"
#include "views/view.h"

namespace views {

// An interface implemented by a View that has text that can be selected.
class VIEWS_EXPORT TouchSelectionClientView
    : public View,
      public ui::SimpleMenuModel::Delegate {
 public:
  // Select everything between start and end (points are in view's local
  // coordinate system). |start| is the logical start and |end| is the logical
  // end of selection. Visually, |start| may lie after |end|.
  virtual void SelectRect(const gfx::Point& start, const gfx::Point& end) = 0;

 protected:
  virtual ~TouchSelectionClientView() {}
};

// This defines the callback interface for other code to be notified of changes
// in the state of a TouchSelectionClientView.
class VIEWS_EXPORT TouchSelectionController {
 public:
  virtual ~TouchSelectionController() {}

  // Creates a TouchSelectionController. Caller owns the returned object.
  static TouchSelectionController* create(
      TouchSelectionClientView* client_view);

  // Notification that the text selection in TouchSelectionClientView has
  // changed. p1 and p2 are lower corners of the start and end of selection:
  // ____________________________________
  // | textfield with |selected text|   |
  // ------------------------------------
  //                  ^p1           ^p2
  //
  // p1 is always the start and p2 is always the end of selection. Hence,
  // p1 could be to the right of p2 in the figure above.
  virtual void SelectionChanged(const gfx::Point& p1, const gfx::Point& p2) = 0;

  // Notification that the TouchSelectionClientView has lost focus.
  virtual void ClientViewLostFocus() = 0;
};

}  // namespace views

#endif  // VIEWS_TOUCHUI_TOUCH_SELECTION_CONTROLLER_H_