Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Side by Side Diff: ui/gfx/win/scaling_util.h

Issue 1813493002: COMPLETED PREVIEW Migrate to Display Placement (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gfxmove
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/win/rect_util_unittest.cc ('k') | ui/gfx/win/scaling_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_GFX_WIN_RECT_UTIL_H_ 5 #ifndef UI_GFX_WIN_RECT_UTIL_H_
6 #define UI_GFX_WIN_RECT_UTIL_H_ 6 #define UI_GFX_WIN_RECT_UTIL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/memory/scoped_ptr.h"
11 #include "ui/gfx/display_layout.h"
10 #include "ui/gfx/gfx_export.h" 12 #include "ui/gfx/gfx_export.h"
13 #include "ui/gfx/win/display_info.h"
11 14
12 namespace gfx { 15 namespace gfx {
13 16
14 class Rect; 17 class Rect;
15 18
16 namespace win { 19 namespace win {
17 20
18 enum class RectEdge { 21 // Whether or not |a| shares and edge with |b|.
19 BOTTOM = 0, 22 GFX_EXPORT bool DisplayInfosTouch(const gfx::win::DisplayInfo& a,
20 LEFT = 1, 23 const gfx::win::DisplayInfo& b);
21 TOP = 2,
22 RIGHT = 3,
23 NONE = 4,
24 };
25 24
26 // Returns |ref|'s RectEdge touching |test|.
27 // Returns RectEdge::NONE if |ref| and |test| do not touch.
28 // At corners, the bottom corners are clamped to BOTTOM, the upper left corner
29 // is clamped to LEFT and the upper right corner is clamped to TOP.
30 GFX_EXPORT RectEdge FindTouchingRectEdge(const gfx::Rect& ref,
31 const gfx::Rect& test);
32 25
33 // Returns a scaled and position rect from |unscaled_rect|, positioned against 26 // Returns a DisplayPlacement for |current| relative to |parent|.
34 // |ref_scaled_rect| based off of the original edge positioning on 27 // Note that DisplayPlacement's are always in DIPs, so this also performs the
35 // |ref_unscaled_rect|, and downscaled by |unscaled_rect_scale_factor|. 28 // required scaling.
36 // As such, |unscaled_rect| and |ref_unscaled_rect| must be touching rectangles.
37 // 29 //
38 // Examples: 30 // Examples (The offset is indicated by the arrow.):
39 // Scaled and Unscaled Coordinates 31 // Scaled and Unscaled Coordinates
40 // +--------------+ Since both rectangles are of the same scale 32 // +--------------+ + Since both DisplayInfos are of the same scale
41 // | | factor, relative positions remain the same. 33 // | | | factor, relative positions remain the same.
42 // | | 34 // | Parent | V
43 // | REF 1x +----------+ 35 // | 1x +----------+
44 // | | | 36 // | | |
45 // +--------------+ 1x | 37 // +--------------+ Current |
46 // | | 38 // | 1x |
47 // +----------+ 39 // +----------+
48 // 40 //
49 // Unscaled Coordinates 41 // Unscaled Coordinates
50 // +--------------+ The 2x rectangle is scaled down while 42 // +--------------+ The 2x DisplayInfo is offset to maintain a
51 // | | maintaining a similar neighboring relationship 43 // | | similar neighboring relationship with the 1x
52 // | | with the REF 1x rectangle. 44 // | Parent | parent.
53 // | REF 1x +----------+ 45 // | 1x +----------+
54 // | | | 46 // | | |
55 // +--------------+ 2x | 47 // +--------------+ Current |
56 // | | 48 // | 2x |
57 // +----------+ 49 // +----------+
58 // Scaled Coordinates 50 // Scaled Coordinates
59 // +--------------+ 51 // +--------------+ +
60 // | | 52 // | | |
61 // | | 53 // | Parent | |
62 // | REF 1x | 54 // | 1x | V
63 // | +-----+ 55 // | +-----+
64 // +--------------+ 2x | 56 // +--------------+ C 2x|
65 // +-----+ 57 // +-----+
66 // 58 //
67 // Unscaled Coordinates 59 // Unscaled Coordinates
68 // +--------------+ The reference rectangle has been scaled by 2x 60 // +--------------+ The parent DisplayInfo has a 2x scale factor.
69 // | | from |ref_unscaled_rect| to |ref_scaled_rect|. 61 // | | The offset is adjusted to maintain the
70 // | | ScaleAndPositionRect maintains the same 62 // | | relative positioning of the 1x DisplayInfo in
71 // | REF 2x +----------+ relative positioning of the unscaled rect in 63 // | Parent +----------+ the scaled coordinate space.
72 // | | | the scaled coordinate space. 64 // | 2x | |
73 // | | | 65 // | | Current |
74 // | | 1x | 66 // | | 1x |
75 // +--------------+ | 67 // +--------------+ |
76 // | | 68 // | |
77 // +----------+ 69 // +----------+
78 // Scaled Coordinates 70 // Scaled Coordinates
79 // +-------+ 71 // +-------+ +
80 // | | 72 // | | V
81 // | REF 2x+----------+ 73 // | Parent+----------+
82 // | | | 74 // | 2x | |
83 // +-------+ | 75 // +-------+ Current |
84 // | 1x | 76 // | 1x |
85 // | | 77 // | |
86 // | | 78 // | |
87 // +----------+ 79 // +----------+
88 GFX_EXPORT gfx::Rect ScaleAndPositionRect(const gfx::Rect& ref_scaled_rect, 80 //
89 const gfx::Rect& ref_unscaled_rect, 81 // Scaled and Unscaled Coordinates
90 const gfx::Rect& unscaled_rect, 82 // +--------+ If the two DisplayInfos are bottom aligned or
91 float unscaled_rect_scale_factor); 83 // | | right aligned, the DisplayPlacement will
84 // | +--------+ have an offset of 0 relative to the
85 // | | | bottom-right of the DisplayInfo.
86 // | | |
87 // +--------+--------+
88 GFX_EXPORT gfx::DisplayPlacement CalculateDisplayPlacement(
89 const gfx::win::DisplayInfo& parent,
90 const gfx::win::DisplayInfo& current);
92 91
93 // Returns the squared distance between two rects. 92 // Returns the squared distance between two rects.
94 // The distance between two rects is the length of the shortest segment that can 93 // The distance between two rects is the length of the shortest segment that can
95 // be drawn between two rectangles. This segment generally connects two opposing 94 // be drawn between two rectangles. This segment generally connects two opposing
96 // corners between rectangles like this... 95 // corners between rectangles like this...
97 // 96 //
98 // +----------+ 97 // +----------+
99 // | | 98 // | |
100 // +----------+ 99 // +----------+
101 // \ <--- Shortest Segment 100 // \ <--- Shortest Segment
(...skipping 19 matching lines...) Expand all
121 // 120 //
122 // The squared distance is used to avoid taking the square root as the common 121 // The squared distance is used to avoid taking the square root as the common
123 // usage is to compare distances greater than 1 unit. 122 // usage is to compare distances greater than 1 unit.
124 GFX_EXPORT int64_t SquaredDistanceBetweenRects(const gfx::Rect& ref, 123 GFX_EXPORT int64_t SquaredDistanceBetweenRects(const gfx::Rect& ref,
125 const gfx::Rect& rect); 124 const gfx::Rect& rect);
126 125
127 } // namespace win 126 } // namespace win
128 } // namespace gfx 127 } // namespace gfx
129 128
130 #endif // UI_GFX_WIN_RECT_UTIL_H_ 129 #endif // UI_GFX_WIN_RECT_UTIL_H_
OLDNEW
« no previous file with comments | « ui/gfx/win/rect_util_unittest.cc ('k') | ui/gfx/win/scaling_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698