Skip to content

Commit

Permalink
Make functions named XXXInWindow() actually use a NativeWindow.
Browse files Browse the repository at this point in the history
That seems more consistent to me.

Bug: none
Change-Id: I962a8e1eee04a33436157dc132e81e0231c0d088
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2147079
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758525}
  • Loading branch information
pkasting authored and Commit Bot committed Apr 13, 2020
1 parent 98fd13b commit 03f91d5
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 30 deletions.
8 changes: 4 additions & 4 deletions ui/display/screen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ void Screen::SetDisplayForNewWindows(int64_t display_id) {
display_id_for_new_windows_ = display_id;
}

gfx::Rect Screen::ScreenToDIPRectInWindow(gfx::NativeView view,
gfx::Rect Screen::ScreenToDIPRectInWindow(gfx::NativeWindow window,
const gfx::Rect& screen_rect) const {
float scale = GetDisplayNearestView(view).device_scale_factor();
float scale = GetDisplayNearestWindow(window).device_scale_factor();
return ScaleToEnclosingRect(screen_rect, 1.0f / scale);
}

gfx::Rect Screen::DIPToScreenRectInWindow(gfx::NativeView view,
gfx::Rect Screen::DIPToScreenRectInWindow(gfx::NativeWindow window,
const gfx::Rect& dip_rect) const {
float scale = GetDisplayNearestView(view).device_scale_factor();
float scale = GetDisplayNearestWindow(window).device_scale_factor();
return ScaleToEnclosingRect(dip_rect, scale);
}

Expand Down
18 changes: 10 additions & 8 deletions ui/display/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,18 @@ class DISPLAY_EXPORT Screen {
virtual void AddObserver(DisplayObserver* observer) = 0;
virtual void RemoveObserver(DisplayObserver* observer) = 0;

// Converts |screen_rect| to DIP coordinates in the context of |view| clamping
// to the enclosing rect if the coordinates do not fall on pixel boundaries.
// If |view| is null, the primary display is used as the context.
virtual gfx::Rect ScreenToDIPRectInWindow(gfx::NativeView view,
// Converts |screen_rect| to DIP coordinates in the context of |window|
// clamping to the enclosing rect if the coordinates do not fall on pixel
// boundaries. If |window| is null, the primary display is used as the
// context.
virtual gfx::Rect ScreenToDIPRectInWindow(gfx::NativeWindow window,
const gfx::Rect& screen_rect) const;

// Converts |dip_rect| to screen coordinates in the context of |view| clamping
// to the enclosing rect if the coordinates do not fall on pixel boundaries.
// If |view| is null, the primary display is used as the context.
virtual gfx::Rect DIPToScreenRectInWindow(gfx::NativeView view,
// Converts |dip_rect| to screen coordinates in the context of |window|
// clamping to the enclosing rect if the coordinates do not fall on pixel
// boundaries. If |window| is null, the primary display is used as the
// context.
virtual gfx::Rect DIPToScreenRectInWindow(gfx::NativeWindow window,
const gfx::Rect& dip_rect) const;

// Returns true if the display with |display_id| is found and returns that
Expand Down
12 changes: 6 additions & 6 deletions ui/display/win/screen_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ void ScreenWin::SetHDREnabled(bool hdr_enabled) {
}
}

HWND ScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const {
HWND ScreenWin::GetHWNDFromNativeWindow(gfx::NativeWindow window) const {
NOTREACHED();
return nullptr;
}
Expand Down Expand Up @@ -678,7 +678,7 @@ const std::vector<Display>& ScreenWin::GetAllDisplays() const {
}

Display ScreenWin::GetDisplayNearestWindow(gfx::NativeWindow window) const {
const HWND window_hwnd = window ? GetHWNDFromNativeView(window) : nullptr;
const HWND window_hwnd = window ? GetHWNDFromNativeWindow(window) : nullptr;
// When |window| isn't rooted to a display, we should just return the default
// display so we get some correct display information like the scaling factor.
return window_hwnd ? GetScreenWinDisplayNearestHWND(window_hwnd).display()
Expand Down Expand Up @@ -707,15 +707,15 @@ void ScreenWin::RemoveObserver(DisplayObserver* observer) {
}

gfx::Rect ScreenWin::ScreenToDIPRectInWindow(
gfx::NativeView view,
gfx::NativeWindow window,
const gfx::Rect& screen_rect) const {
const HWND hwnd = view ? GetHWNDFromNativeView(view) : nullptr;
const HWND hwnd = window ? GetHWNDFromNativeWindow(window) : nullptr;
return ScreenToDIPRect(hwnd, screen_rect);
}

gfx::Rect ScreenWin::DIPToScreenRectInWindow(gfx::NativeView view,
gfx::Rect ScreenWin::DIPToScreenRectInWindow(gfx::NativeWindow window,
const gfx::Rect& dip_rect) const {
const HWND hwnd = view ? GetHWNDFromNativeView(view) : nullptr;
const HWND hwnd = window ? GetHWNDFromNativeWindow(window) : nullptr;
return DIPToScreenRect(hwnd, dip_rect);
}

Expand Down
13 changes: 7 additions & 6 deletions ui/display/win/screen_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ class DISPLAY_EXPORT ScreenWin : public Screen,
// to return that HDR is supported.
static void SetHDREnabled(bool hdr_enabled);

// Returns the HWND associated with the NativeView.
virtual HWND GetHWNDFromNativeView(gfx::NativeView view) const;
// Returns the HWND associated with the NativeWindow.
virtual HWND GetHWNDFromNativeWindow(gfx::NativeWindow view) const;

// Returns the NativeView associated with the HWND.
// Returns the NativeWindow associated with the HWND.
virtual gfx::NativeWindow GetNativeWindowFromHWND(HWND hwnd) const;

protected:
Expand All @@ -170,9 +170,10 @@ class DISPLAY_EXPORT ScreenWin : public Screen,
void AddObserver(DisplayObserver* observer) override;
void RemoveObserver(DisplayObserver* observer) override;
gfx::Rect ScreenToDIPRectInWindow(
gfx::NativeView view, const gfx::Rect& screen_rect) const override;
gfx::Rect DIPToScreenRectInWindow(
gfx::NativeView view, const gfx::Rect& dip_rect) const override;
gfx::NativeWindow window,
const gfx::Rect& screen_rect) const override;
gfx::Rect DIPToScreenRectInWindow(gfx::NativeWindow window,
const gfx::Rect& dip_rect) const override;

// ColorProfileReader::Client:
void OnColorProfilesChanged() override;
Expand Down
8 changes: 4 additions & 4 deletions ui/display/win/screen_win_unittest.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Copyright 2015 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.

Expand Down Expand Up @@ -43,9 +43,9 @@ class TestScreenWin : public ScreenWin {

protected:
// win::ScreenWin:
HWND GetHWNDFromNativeView(gfx::NativeView window) const override {
// NativeView is only used as an identifier in these tests, so interchange
// a NativeView for an HWND for convenience.
HWND GetHWNDFromNativeWindow(gfx::NativeWindow window) const override {
// NativeWindow is only used as an identifier in these tests, so interchange
// a NativeWindow for an HWND for convenience.
return reinterpret_cast<HWND>(window);
}

Expand Down
2 changes: 1 addition & 1 deletion ui/views/widget/desktop_aura/desktop_screen_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ display::Display DesktopScreenWin::GetDisplayMatching(
return GetDisplayNearestPoint(match_rect.CenterPoint());
}

HWND DesktopScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const {
HWND DesktopScreenWin::GetHWNDFromNativeWindow(gfx::NativeWindow window) const {
aura::WindowTreeHost* host = window->GetHost();
return host ? host->GetAcceleratedWidget() : nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion ui/views/widget/desktop_aura/desktop_screen_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class VIEWS_EXPORT DesktopScreenWin : public display::win::ScreenWin {
// Overridden from display::win::ScreenWin:
display::Display GetDisplayMatching(
const gfx::Rect& match_rect) const override;
HWND GetHWNDFromNativeView(gfx::NativeView window) const override;
HWND GetHWNDFromNativeWindow(gfx::NativeWindow window) const override;
gfx::NativeWindow GetNativeWindowFromHWND(HWND hwnd) const override;

DISALLOW_COPY_AND_ASSIGN(DesktopScreenWin);
Expand Down

0 comments on commit 03f91d5

Please sign in to comment.