-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chrome: Improve positioning of the "Find" widget (fixes #3461)
The "Find" widget will be excluded from regions near the edges of the window that contain overlays, draggable regions or titlebar.
- Loading branch information
1 parent
17cab6d
commit a39c2a0
Showing
20 changed files
with
630 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright (c) 2022 The Chromium Embedded Framework Authors. All rights | ||
// reserved. Use of this source code is governed by a BSD-style license that | ||
// can be found in the LICENSE file. | ||
|
||
#include "libcef/browser/geometry_util.h" | ||
|
||
#include <algorithm> | ||
|
||
#include "ui/gfx/geometry/rect.h" | ||
|
||
namespace { | ||
|
||
constexpr int kMinWidth = 0; | ||
constexpr int kMinHeight = 0; | ||
|
||
// Makes sure that line segment lies entirely between min and max. | ||
int clamp_segment_start(int start, int len, int min, int max) { | ||
start = std::clamp(start, min, max); | ||
const int end = start + len; | ||
const int excess = end - max; | ||
|
||
if (excess > 0) { | ||
start = start - excess; | ||
} | ||
|
||
return start; | ||
} | ||
|
||
} // namespace | ||
|
||
gfx::Rect MakeVisibleOnScreenRect(const gfx::Rect& rect, | ||
const gfx::Rect& screen) { | ||
const int width = std::clamp(rect.width(), kMinWidth, screen.width()); | ||
const int height = std::clamp(rect.height(), kMinHeight, screen.height()); | ||
|
||
const int right_border = screen.x() + screen.width(); | ||
const int x = clamp_segment_start(rect.x(), width, screen.x(), right_border); | ||
|
||
const int bottom_border = screen.y() + screen.height(); | ||
const int y = | ||
clamp_segment_start(rect.y(), height, screen.y(), bottom_border); | ||
|
||
return gfx::Rect(x, y, width, height); | ||
} | ||
|
||
gfx::Rect SubtractOverlayFromBoundingBox(const gfx::Rect& bounds, | ||
const gfx::Rect& overlay, | ||
int max_distance) { | ||
if (overlay.Contains(bounds)) { | ||
// Early exit; |bounds| is completely inside |overlay|. | ||
return bounds; | ||
} | ||
|
||
// Portion of |overlay| that is inside |bounds|. | ||
auto overlap = overlay; | ||
overlap.Intersect(bounds); | ||
if (overlap.IsEmpty()) { | ||
// Early exit; |bounds| and |overlay| don't intersect. | ||
return bounds; | ||
} | ||
|
||
gfx::Insets insets; | ||
|
||
if (overlap.width() >= overlap.height()) { | ||
// Wide overlay; maybe inset |bounds| in the Y direction. | ||
const int delta_top = overlap.y() - bounds.y(); | ||
const int delta_bottom = | ||
bounds.y() + bounds.height() - overlap.y() - overlap.height(); | ||
|
||
// Inset from the closest side that meets |max_distance| requirements. | ||
if (delta_top <= delta_bottom && delta_top <= max_distance) { | ||
// Inset from the top. | ||
insets.set_top(delta_top + overlap.height()); | ||
} else if (delta_bottom <= max_distance) { | ||
// Inset from the bottom. | ||
insets.set_bottom(delta_bottom + overlap.height()); | ||
} | ||
} else { | ||
// Tall overlay; maybe inset |bounds| in the X direction. | ||
const int delta_left = overlap.x() - bounds.x(); | ||
const int delta_right = | ||
bounds.x() + bounds.width() - overlap.x() - overlap.width(); | ||
|
||
// Inset from the closest side that meets |max_distance| requirements. | ||
if (delta_left <= delta_right && delta_left <= max_distance) { | ||
// Inset from the left. | ||
insets.set_left(delta_left + overlap.width()); | ||
} else if (delta_right <= max_distance) { | ||
// Inset from the right. | ||
insets.set_right(delta_right + overlap.width()); | ||
} | ||
} | ||
|
||
if (insets.IsEmpty()) { | ||
// |overlay| is too far inside |bounds| to trigger insets. | ||
return bounds; | ||
} | ||
|
||
auto result = bounds; | ||
result.Inset(insets); | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2022 The Chromium Embedded Framework 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 CEF_LIBCEF_BROWSER_GEOMETRY_UTIL_H_ | ||
#define CEF_LIBCEF_BROWSER_GEOMETRY_UTIL_H_ | ||
#pragma once | ||
|
||
namespace gfx { | ||
class Rect; | ||
} | ||
|
||
// Create a new rectangle from the input |rect| rectangle that is fully visible | ||
// on provided |screen_rect| screen. The width and height of the resulting | ||
// rectangle are clamped to the screen width and height respectively if they | ||
// would overflow. | ||
gfx::Rect MakeVisibleOnScreenRect(const gfx::Rect& rect, | ||
const gfx::Rect& screen); | ||
|
||
// Possibly subtract |overlay| from |bounds|. We only want to subtract overlays | ||
// that are inside |bounds| and close to the edges, so |max_distance| is the | ||
// maximum allowed distance between |overlay| and |bounds| extents in order to | ||
// trigger the subtraction. Subtraction will occur from the closest edge. If | ||
// distances are otherwise equal then top will be preferred followed by left. | ||
gfx::Rect SubtractOverlayFromBoundingBox(const gfx::Rect& bounds, | ||
const gfx::Rect& overlay, | ||
int max_distance); | ||
|
||
#endif // CEF_LIBCEF_BROWSER_GEOMETRY_UTIL_H_ |
Oops, something went wrong.