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

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: Add rect_util_unittests to GN 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
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..173d87c8698de8727d3fc51409b56d22f0ed8845
--- /dev/null
+++ b/ui/gfx/win/rect_util.h
@@ -0,0 +1,102 @@
+// 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|.
+GFX_EXPORT RectEdge FindTouchingRectEdge(gfx::Rect ref, gfx::Rect test);
oshima 2016/02/11 22:59:58 const &
robliao 2016/02/12 01:52:53 These actually started as const gfx::Rect& and the
oshima 2016/02/12 23:18:26 For correctness, I'd rely on the unit tests rather
robliao 2016/02/13 01:27:49 Thanks for the intersecting rect pointer. I probab
oshima 2016/02/16 06:03:26 Ok. I'll leave the rest to owners review. (I don't
+
+// Returns a scaled and positioned rect based off of target_rect and context.
+// The reference rectangle and target rectangle may scale at different rates.
+// This function attempts to preserve the relative positioning of the target
+// rectangle with respect to the scaled rectangle in the face of differing
+// scale factors.
+//
+// Examples:
+// +--------------+ Since both rectangles are of the same
+// | | scale factor, positions and sizes
+// | | remain the same.
+// | REF 1x +----------+
+// | | |
+// +--------------+ 1x |
+// | |
+// +----------+
+//
+// Original
+// +--------------+ The 2x rectangle is scaled down while
+// | | maintaining a similar neighboring relationship
+// | | with the 1x rectangle.
+// | REF 1x +----------+
+// | | |
+// +--------------+ 2x |
+// | |
+// +----------+
+// Scaled
+// +--------------+
+// | |
+// | |
+// | REF 1x |
+// | +-----+
+// +--------------+ 2x |
+// +-----+
+GFX_EXPORT gfx::Rect ScaleAndPositionRect(gfx::Rect ref_scaled_rect,
+ gfx::Rect ref_original_rect,
+ gfx::Rect target_rect,
+ float target_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 generally the segment 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 greather than 1 unit.
+GFX_EXPORT int64_t SquaredDistanceBetweenRects(gfx::Rect ref, gfx::Rect rect);
+
+} // namespace win
+} // namespace gfx
+
+#endif // UI_GFX_WIN_RECT_UTIL_H_

Powered by Google App Engine
This is Rietveld 408576698