Browse Source

fix: sync api::Screen wrapper method sigs to upstream (#38631)

refactor: sync api::Screen getter sigs to upstream

ui::Display GetAllDisplays(), GetPrimaryDisplay(), GetDisplayMatching(),
and GetDisplayNearestPoint() methods are all const, so make our wrappers
const too.

ui::Display GetAllDisplays() returns a const reference, so make our
wrapper return a const reference too. This avoids creating a new
std::vector<display::Display> each time it's called.

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <[email protected]>
trop[bot] 1 year ago
parent
commit
7254da337b
2 changed files with 12 additions and 20 deletions
  1. 0 16
      shell/browser/api/electron_api_screen.cc
  2. 12 4
      shell/browser/api/electron_api_screen.h

+ 0 - 16
shell/browser/api/electron_api_screen.cc

@@ -87,22 +87,6 @@ gfx::Point Screen::GetCursorScreenPoint(v8::Isolate* isolate) {
   return screen_->GetCursorScreenPoint();
 }
 
-display::Display Screen::GetPrimaryDisplay() {
-  return screen_->GetPrimaryDisplay();
-}
-
-std::vector<display::Display> Screen::GetAllDisplays() {
-  return screen_->GetAllDisplays();
-}
-
-display::Display Screen::GetDisplayNearestPoint(const gfx::Point& point) {
-  return screen_->GetDisplayNearestPoint(point);
-}
-
-display::Display Screen::GetDisplayMatching(const gfx::Rect& match_rect) {
-  return screen_->GetDisplayMatching(match_rect);
-}
-
 #if BUILDFLAG(IS_WIN)
 
 static gfx::Rect ScreenToDIPRect(electron::NativeWindow* window,

+ 12 - 4
shell/browser/api/electron_api_screen.h

@@ -41,10 +41,18 @@ class Screen : public gin::Wrappable<Screen>,
   ~Screen() override;
 
   gfx::Point GetCursorScreenPoint(v8::Isolate* isolate);
-  display::Display GetPrimaryDisplay();
-  std::vector<display::Display> GetAllDisplays();
-  display::Display GetDisplayNearestPoint(const gfx::Point& point);
-  display::Display GetDisplayMatching(const gfx::Rect& match_rect);
+  display::Display GetPrimaryDisplay() const {
+    return screen_->GetPrimaryDisplay();
+  }
+  const std::vector<display::Display>& GetAllDisplays() const {
+    return screen_->GetAllDisplays();
+  }
+  display::Display GetDisplayNearestPoint(const gfx::Point& point) const {
+    return screen_->GetDisplayNearestPoint(point);
+  }
+  display::Display GetDisplayMatching(const gfx::Rect& match_rect) const {
+    return screen_->GetDisplayMatching(match_rect);
+  }
 
   // display::DisplayObserver:
   void OnDisplayAdded(const display::Display& new_display) override;