• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include "modules/desktop_capture/win/selected_window_context.h"
12 
13 namespace webrtc {
14 
SelectedWindowContext(HWND selected_window,DesktopRect selected_window_rect,WindowCaptureHelperWin * window_capture_helper)15 SelectedWindowContext::SelectedWindowContext(
16     HWND selected_window,
17     DesktopRect selected_window_rect,
18     WindowCaptureHelperWin* window_capture_helper)
19     : selected_window_(selected_window),
20       selected_window_rect_(selected_window_rect),
21       window_capture_helper_(window_capture_helper) {
22   selected_window_thread_id_ =
23       GetWindowThreadProcessId(selected_window, &selected_window_process_id_);
24 }
25 
IsSelectedWindowValid() const26 bool SelectedWindowContext::IsSelectedWindowValid() const {
27   return selected_window_thread_id_ != 0;
28 }
29 
IsWindowOwnedBySelectedWindow(HWND hwnd) const30 bool SelectedWindowContext::IsWindowOwnedBySelectedWindow(HWND hwnd) const {
31   // This check works for drop-down menus & dialog pop-up windows.
32   if (GetAncestor(hwnd, GA_ROOTOWNER) == selected_window_) {
33     return true;
34   }
35 
36   // Assume that all other windows are unrelated to the selected window.
37   // This will cause some windows that are actually related to be missed,
38   // e.g. context menus and tool-tips, but avoids the risk of capturing
39   // unrelated windows. Using heuristics such as matching the thread and
40   // process Ids suffers from false-positives, e.g. in multi-document
41   // applications.
42 
43   return false;
44 }
45 
IsWindowOverlappingSelectedWindow(HWND hwnd) const46 bool SelectedWindowContext::IsWindowOverlappingSelectedWindow(HWND hwnd) const {
47   return window_capture_helper_->AreWindowsOverlapping(hwnd, selected_window_,
48                                                        selected_window_rect_);
49 }
50 
selected_window() const51 HWND SelectedWindowContext::selected_window() const {
52   return selected_window_;
53 }
54 
window_capture_helper() const55 WindowCaptureHelperWin* SelectedWindowContext::window_capture_helper() const {
56   return window_capture_helper_;
57 }
58 
59 }  // namespace webrtc
60