File: local_process_window_finder_win.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (61 lines) | stat: -rw-r--r-- 2,376 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/display/win/local_process_window_finder_win.h"

#include "base/win/windows_version.h"
#include "ui/display/win/screen_win.h"
#include "ui/gfx/win/hwnd_util.h"

namespace display::win {

// static
gfx::NativeWindow LocalProcessWindowFinder::GetProcessWindowAtPoint(
    const gfx::Point& screen_loc,
    const std::set<HWND>& ignore,
    ScreenWin* screen_win) {
  LocalProcessWindowFinder finder(screen_loc, screen_win, ignore);
  return finder.result_ ? screen_win->GetNativeWindowFromHWND(finder.result_)
                        : nullptr;
}

bool LocalProcessWindowFinder::ShouldStopIterating(HWND hwnd) {
  // If the host knows `hwnd` is not on the current_workspace, return.
  gfx::NativeWindow native_win = screen_win_->GetNativeWindowFromHWND(hwnd);
  std::optional<bool> on_current_workspace;
  if (native_win) {
    on_current_workspace =
        screen_win_->IsWindowOnCurrentVirtualDesktop(native_win);
  }
  if (on_current_workspace == false)
    return false;

  // Ignore non visible  and cloaked windows. This will include windows not on
  // the current virtual desktop, which are cloaked.
  RECT r;
  if (!IsWindowVisible(hwnd) || gfx::IsWindowCloaked(hwnd) ||
      !GetWindowRect(hwnd, &r) || !PtInRect(&r, screen_loc_.ToPOINT())) {
    return false;  // Window is not at `screen_loc_`.
  }

  // The window is at the correct position on the screen.
  // Don't set `result_` if the window is occluded, because there is at least
  // one window covering the browser window. E.g., tab drag drop shouldn't
  // drop on an occluded browser window.
  if (!native_win || !screen_win_->IsNativeWindowOccluded(native_win))
    result_ = hwnd;
  return true;
}

LocalProcessWindowFinder::LocalProcessWindowFinder(const gfx::Point& screen_loc,
                                                   ScreenWin* screen_win,
                                                   const std::set<HWND>& ignore)
    : BaseWindowFinderWin(ignore), screen_win_(screen_win) {
  screen_loc_ = display::win::GetScreenWin()->DIPToScreenPoint(screen_loc);
  EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, as_lparam());
}

LocalProcessWindowFinder::~LocalProcessWindowFinder() = default;

}  // namespace display::win