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

Unified Diff: ui/gfx/win/rect_util.h

Issue 1679393002: Multiple DPI Tracking for ScreenWin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR Feedback EXCEPT rect_util Rename Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/win/dpi.cc ('k') | ui/gfx/win/rect_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/win/rect_util.h
diff --git a/ui/gfx/win/rect_util.h b/ui/gfx/win/rect_util.h
new file mode 100644
index 0000000000000000000000000000000000000000..60c109d335bfc89b8352f65ac69fa2008baadae4
--- /dev/null
+++ b/ui/gfx/win/rect_util.h
@@ -0,0 +1,130 @@
+// Copyright 2016 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 UI_GFX_WIN_RECT_UTIL_H_
+#define UI_GFX_WIN_RECT_UTIL_H_
+
+#include <stdint.h>
+
+#include "ui/gfx/gfx_export.h"
+
+namespace gfx {
+
+class Rect;
+
+namespace win {
+
+enum class RectEdge {
+ BOTTOM = 0,
+ LEFT = 1,
+ TOP = 2,
+ RIGHT = 3,
+ NONE = 4,
+};
+
+// Returns |ref|'s RectEdge touching |test|.
+// Returns RectEdge::NONE if |ref| and |test| do not touch.
+// At corners, the bottom corners are clamped to BOTTOM, the upper left corner
+// is clamped to LEFT and the upper right corner is clamped to TOP.
+GFX_EXPORT RectEdge FindTouchingRectEdge(const gfx::Rect& ref,
+ const gfx::Rect& test);
+
+// Returns a scaled and position rect from |unscaled_rect|, positioned against
+// |ref_scaled_rect| based off of the original edge positioning on
+// |ref_unscaled_rect|, and downscaled by |unscaled_rect_scale_factor|.
+// As such, |unscaled_rect| and |ref_unscaled_rect| must be touching rectangles.
+//
+// Examples:
+// Scaled and Unscaled Coordinates
+// +--------------+ Since both rectangles are of the same scale
+// | | factor, relative positions remain the same.
+// | |
+// | REF 1x +----------+
+// | | |
+// +--------------+ 1x |
+// | |
+// +----------+
+//
+// Unscaled Coordinates
+// +--------------+ The 2x rectangle is scaled down while
+// | | maintaining a similar neighboring relationship
+// | | with the REF 1x rectangle.
+// | REF 1x +----------+
+// | | |
+// +--------------+ 2x |
+// | |
+// +----------+
+// Scaled Coordinates
+// +--------------+
+// | |
+// | |
+// | REF 1x |
+// | +-----+
+// +--------------+ 2x |
+// +-----+
+//
+// Unscaled Coordinates
+// +--------------+ The reference rectangle has been scaled by 2x
+// | | from |ref_unscaled_rect| to |ref_scaled_rect|.
+// | | ScaleAndPositionRect maintains the same
+// | REF 2x +----------+ relative positioning of the unscaled rect in
+// | | | the scaled coordinate space.
+// | | |
+// | | 1x |
+// +--------------+ |
+// | |
+// +----------+
+// Scaled Coordinates
+// +-------+
+// | |
+// | REF 2x+----------+
+// | | |
+// +-------+ |
+// | 1x |
+// | |
+// | |
+// +----------+
+GFX_EXPORT gfx::Rect ScaleAndPositionRect(const gfx::Rect& ref_scaled_rect,
+ const gfx::Rect& ref_unscaled_rect,
+ const gfx::Rect& unscaled_rect,
+ float unscaled_rect_scale_factor);
+
+// Returns the squared distance between two rects.
+// The distance between two rects is the length of the shortest segment that can
+// be drawn between two rectangles. This segment generally connects two opposing
+// corners between rectangles like this...
+//
+// +----------+
+// | |
+// +----------+
+// \ <--- Shortest Segment
+// \
+// +---+
+// | |
+// | |
+// +---+
+//
+// For rectangles that share coordinates within the same axis, that generally
+// means the segment is parallel to the axis and perpendicular to the edges.
+//
+// One of many shortest segments
+// +----------+ / \ +--------+
+// | | | \ | |
+// | | V +---+ \ +--------+
+// | |-----| | \-->|
+// +----------+ | | +----+
+// | | | |
+// +---+ +----+
+//
+// For rectangles that intersect each other, the distance is 0.
+//
+// The squared distance is used to avoid taking the square root as the common
+// usage is to compare distances greater than 1 unit.
+GFX_EXPORT int64_t SquaredDistanceBetweenRects(const gfx::Rect& ref,
+ const gfx::Rect& rect);
+
+} // namespace win
+} // namespace gfx
+
+#endif // UI_GFX_WIN_RECT_UTIL_H_
« no previous file with comments | « ui/gfx/win/dpi.cc ('k') | ui/gfx/win/rect_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698