• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4 
5 #ifndef CEF_TESTS_CEFCLIENT_BROWSER_ROOT_WINDOW_WIN_H_
6 #define CEF_TESTS_CEFCLIENT_BROWSER_ROOT_WINDOW_WIN_H_
7 #pragma once
8 
9 #include <windows.h>
10 
11 #include <commdlg.h>
12 
13 #include <memory>
14 #include <string>
15 
16 #include "tests/cefclient/browser/browser_window.h"
17 #include "tests/cefclient/browser/root_window.h"
18 
19 namespace client {
20 
21 // Windows implementation of a top-level native window in the browser process.
22 // The methods of this class must be called on the main thread unless otherwise
23 // indicated.
24 class RootWindowWin : public RootWindow, public BrowserWindow::Delegate {
25  public:
26   // Constructor may be called on any thread.
27   RootWindowWin();
28   ~RootWindowWin();
29 
30   // RootWindow methods.
31   void Init(RootWindow::Delegate* delegate,
32             std::unique_ptr<RootWindowConfig> config,
33             const CefBrowserSettings& settings) override;
34   void InitAsPopup(RootWindow::Delegate* delegate,
35                    bool with_controls,
36                    bool with_osr,
37                    const CefPopupFeatures& popupFeatures,
38                    CefWindowInfo& windowInfo,
39                    CefRefPtr<CefClient>& client,
40                    CefBrowserSettings& settings) override;
41   void Show(ShowMode mode) override;
42   void Hide() override;
43   void SetBounds(int x, int y, size_t width, size_t height) override;
44   void Close(bool force) override;
45   void SetDeviceScaleFactor(float device_scale_factor) override;
46   float GetDeviceScaleFactor() const override;
47   CefRefPtr<CefBrowser> GetBrowser() const override;
48   ClientWindowHandle GetWindowHandle() const override;
49   bool WithWindowlessRendering() const override;
50   bool WithExtension() const override;
51 
52  private:
53   void CreateBrowserWindow(const std::string& startup_url);
54   void CreateRootWindow(const CefBrowserSettings& settings,
55                         bool initially_hidden);
56 
57   // Register the root window class.
58   static void RegisterRootClass(HINSTANCE hInstance,
59                                 const std::wstring& window_class,
60                                 HBRUSH background_brush);
61 
62   // Window procedure for the edit field.
63   static LRESULT CALLBACK EditWndProc(HWND hWnd,
64                                       UINT message,
65                                       WPARAM wParam,
66                                       LPARAM lParam);
67 
68   // Window procedure for the find dialog.
69   static LRESULT CALLBACK FindWndProc(HWND hWnd,
70                                       UINT message,
71                                       WPARAM wParam,
72                                       LPARAM lParam);
73 
74   // Window procedure for the root window.
75   static LRESULT CALLBACK RootWndProc(HWND hWnd,
76                                       UINT message,
77                                       WPARAM wParam,
78                                       LPARAM lParam);
79 
80   // Event handlers.
81   void OnPaint();
82   void OnFocus();
83   void OnActivate(bool active);
84   void OnSize(bool minimized);
85   void OnMove();
86   void OnDpiChanged(WPARAM wParam, LPARAM lParam);
87   bool OnEraseBkgnd();
88   bool OnCommand(UINT id);
89   void OnFind();
90   void OnFindEvent();
91   void OnAbout();
92   void OnNCCreate(LPCREATESTRUCT lpCreateStruct);
93   void OnCreate(LPCREATESTRUCT lpCreateStruct);
94   bool OnClose();
95   void OnDestroyed();
96 
97   // BrowserWindow::Delegate methods.
98   void OnBrowserCreated(CefRefPtr<CefBrowser> browser) override;
99   void OnBrowserWindowDestroyed() override;
100   void OnSetAddress(const std::string& url) override;
101   void OnSetTitle(const std::string& title) override;
102   void OnSetFullscreen(bool fullscreen) override;
103   void OnAutoResize(const CefSize& new_size) override;
104   void OnSetLoadingState(bool isLoading,
105                          bool canGoBack,
106                          bool canGoForward) override;
107   void OnSetDraggableRegions(
108       const std::vector<CefDraggableRegion>& regions) override;
109 
110   void NotifyDestroyedIfDone();
111 
112   // After initialization all members are only accessed on the main thread.
113   // Members set during initialization.
114   bool with_controls_;
115   bool always_on_top_;
116   bool with_osr_;
117   bool with_extension_;
118   bool is_popup_;
119   RECT start_rect_;
120   std::unique_ptr<BrowserWindow> browser_window_;
121   CefBrowserSettings browser_settings_;
122   bool initialized_;
123 
124   // Main window.
125   HWND hwnd_;
126 
127   // Draggable region.
128   HRGN draggable_region_;
129 
130   // Font for buttons and text fields.
131   HFONT font_;
132   int font_height_;
133 
134   // Buttons.
135   HWND back_hwnd_;
136   HWND forward_hwnd_;
137   HWND reload_hwnd_;
138   HWND stop_hwnd_;
139 
140   // URL text field.
141   HWND edit_hwnd_;
142   WNDPROC edit_wndproc_old_;
143 
144   // Find dialog.
145   HWND find_hwnd_;
146   UINT find_message_id_;
147   WNDPROC find_wndproc_old_;
148 
149   // Find dialog state.
150   FINDREPLACE find_state_;
151   WCHAR find_buff_[80];
152   std::wstring find_what_last_;
153   bool find_next_;
154   bool find_match_case_last_;
155 
156   bool window_destroyed_;
157   bool browser_destroyed_;
158 
159   bool called_enable_non_client_dpi_scaling_;
160 
161   DISALLOW_COPY_AND_ASSIGN(RootWindowWin);
162 };
163 
164 }  // namespace client
165 
166 #endif  // CEF_TESTS_CEFCLIENT_BROWSER_ROOT_WINDOW_WIN_H_
167