File: selection_bound.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (105 lines) | stat: -rw-r--r-- 3,499 bytes parent folder | download | duplicates (4)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GFX_SELECTION_BOUND_H_
#define UI_GFX_SELECTION_BOUND_H_

#include "base/component_export.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h"

namespace gfx {

class Rect;
class RectF;

// Bound of a selection end-point.
class COMPONENT_EXPORT(GFX) SelectionBound {
 public:
  enum Type {
    // The LEFT and RIGHT hand side of a selection bound.
    LEFT,
    RIGHT,
    // Used when a selection is zero width (a caret) and the selection handle
    // should be shown.
    CENTER,
    // Used when a selection is zero width (a caret), but the selection handle
    // should not be shown.
    HIDDEN,
    // No selection.
    EMPTY,
    LAST = EMPTY
  };

  SelectionBound();
  SelectionBound(const SelectionBound& other);
  ~SelectionBound();

  Type type() const { return type_; }
  void set_type(Type value) { type_ = value; }

  const gfx::PointF& edge_start() const { return edge_start_; }
  const gfx::PointF& visible_edge_start() const { return visible_edge_start_; }
  const gfx::Point& edge_start_rounded() const { return edge_start_rounded_; }
  void SetEdgeStart(const gfx::PointF& value);
  void SetVisibleEdgeStart(const gfx::PointF& value);

  const gfx::PointF& edge_end() const { return edge_end_; }
  const gfx::PointF& visible_edge_end() const { return visible_edge_end_; }
  const gfx::Point& edge_end_rounded() const { return edge_end_rounded_; }
  void SetEdgeEnd(const gfx::PointF& value);
  void SetVisibleEdgeEnd(const gfx::PointF& value);

  void SetEdge(const gfx::PointF& start, const gfx::PointF& end);
  void SetVisibleEdge(const gfx::PointF& start, const gfx::PointF& end);

  bool visible() const { return visible_; }
  void set_visible(bool value) { visible_ = value; }

  // Returns the vertical difference between rounded start and end.
  int GetHeight() const;

  // Returns whether the type is one that should show a selection handle.
  bool HasHandle() const { return !(type_ == EMPTY || type_ == HIDDEN); }

  std::string ToString() const;

 private:
  Type type_;
  // The actual bounds of a selection end-point mgiht be invisible for
  // occlusion.
  gfx::PointF edge_start_;
  gfx::PointF edge_end_;
  // The visible bounds of a selection, which are equal to the above, when there
  // is no occlusion.
  gfx::PointF visible_edge_start_;
  gfx::PointF visible_edge_end_;
  gfx::Point edge_start_rounded_;
  gfx::Point edge_end_rounded_;
  bool visible_;
};

COMPONENT_EXPORT(GFX)
bool operator==(const SelectionBound& lhs, const SelectionBound& rhs);

COMPONENT_EXPORT(GFX)
gfx::Rect RectBetweenSelectionBounds(const SelectionBound& b1,
                                     const SelectionBound& b2);

COMPONENT_EXPORT(GFX)
gfx::RectF RectFBetweenSelectionBounds(const SelectionBound& b1,
                                       const SelectionBound& b2);

COMPONENT_EXPORT(GFX)
gfx::RectF RectFBetweenVisibleSelectionBounds(const SelectionBound& b1,
                                              const SelectionBound& b2);

// This is declared here for use in gtest-based unit tests but is defined in
// the //ui/gfx:test_support target. Depend on that to use this in your unit
// test. This should not be used in production code - call ToString() instead.
void PrintTo(const SelectionBound& bound, ::std::ostream* os);

}  // namespace gfx

#endif  // UI_GFX_SELECTION_BOUND_H_