OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/web_contents/web_contents_view_win.h" | 5 #include "content/browser/web_contents/web_contents_view_win.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "content/browser/renderer_host/render_view_host_factory.h" | 9 #include "content/browser/renderer_host/render_view_host_factory.h" |
10 #include "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
11 #include "content/browser/renderer_host/render_widget_host_view_win.h" | 11 #include "content/browser/renderer_host/render_widget_host_view_win.h" |
12 #include "content/browser/web_contents/interstitial_page_impl.h" | 12 #include "content/browser/web_contents/interstitial_page_impl.h" |
13 #include "content/browser/web_contents/web_contents_drag_win.h" | 13 #include "content/browser/web_contents/web_contents_drag_win.h" |
14 #include "content/browser/web_contents/web_contents_impl.h" | 14 #include "content/browser/web_contents/web_contents_impl.h" |
15 #include "content/browser/web_contents/web_drag_dest_win.h" | 15 #include "content/browser/web_contents/web_drag_dest_win.h" |
16 #include "content/public/browser/web_contents_delegate.h" | 16 #include "content/public/browser/web_contents_delegate.h" |
17 #include "content/public/browser/web_contents_view_delegate.h" | 17 #include "content/public/browser/web_contents_view_delegate.h" |
| 18 #include "ui/base/win/hidden_window.h" |
18 #include "ui/base/win/hwnd_subclass.h" | 19 #include "ui/base/win/hwnd_subclass.h" |
19 #include "ui/gfx/screen.h" | 20 #include "ui/gfx/screen.h" |
20 | 21 |
21 using content::RenderViewHost; | 22 using content::RenderViewHost; |
22 using content::RenderWidgetHostView; | 23 using content::RenderWidgetHostView; |
23 using content::RenderWidgetHostViewWin; | 24 using content::RenderWidgetHostViewWin; |
24 using content::WebContents; | 25 using content::WebContents; |
25 using content::WebContentsViewDelegate; | 26 using content::WebContentsViewDelegate; |
26 | 27 |
27 namespace content { | 28 namespace content { |
28 WebContentsView* CreateWebContentsView( | 29 WebContentsView* CreateWebContentsView( |
29 WebContentsImpl* web_contents, | 30 WebContentsImpl* web_contents, |
30 WebContentsViewDelegate* delegate, | 31 WebContentsViewDelegate* delegate, |
31 RenderViewHostDelegateView** render_view_host_delegate_view) { | 32 RenderViewHostDelegateView** render_view_host_delegate_view) { |
32 WebContentsViewWin* rv = new WebContentsViewWin(web_contents, delegate); | 33 WebContentsViewWin* rv = new WebContentsViewWin(web_contents, delegate); |
33 *render_view_host_delegate_view = rv; | 34 *render_view_host_delegate_view = rv; |
34 return rv; | 35 return rv; |
35 } | 36 } |
36 } | 37 } |
37 | 38 |
38 namespace { | 39 namespace { |
39 | 40 |
40 // We need to have a parent window for the compositing code to work correctly. | |
41 // | |
42 // A tab will not have a parent HWND whenever it is not active in its | |
43 // host window - for example at creation time and when it's in the | |
44 // background, so we provide a default widget to host them. | |
45 // | |
46 // It may be tempting to use GetDesktopWindow() instead, but this is | |
47 // problematic as the shell sends messages to children of the desktop | |
48 // window that interact poorly with us. | |
49 // | |
50 // See: http://crbug.com/16476 | |
51 class TempParent : public ui::WindowImpl { | |
52 public: | |
53 static TempParent* Get() { | |
54 static TempParent* g_temp_parent; | |
55 if (!g_temp_parent) { | |
56 g_temp_parent = new TempParent(); | |
57 | |
58 g_temp_parent->set_window_style(WS_POPUP); | |
59 g_temp_parent->set_window_ex_style(WS_EX_TOOLWINDOW); | |
60 g_temp_parent->Init(GetDesktopWindow(), gfx::Rect()); | |
61 EnableWindow(g_temp_parent->hwnd(), FALSE); | |
62 } | |
63 return g_temp_parent; | |
64 } | |
65 | |
66 private: | |
67 // Explicitly do nothing in Close. We do this as some external apps may get a | |
68 // handle to this window and attempt to close it. | |
69 void OnClose() { | |
70 } | |
71 | |
72 BEGIN_MSG_MAP_EX(WebContentsViewWin) | |
73 MSG_WM_CLOSE(OnClose) | |
74 END_MSG_MAP() | |
75 }; | |
76 | |
77 typedef std::map<HWND, WebContentsViewWin*> HwndToWcvMap; | 41 typedef std::map<HWND, WebContentsViewWin*> HwndToWcvMap; |
78 HwndToWcvMap hwnd_to_wcv_map; | 42 HwndToWcvMap hwnd_to_wcv_map; |
79 | 43 |
80 void RemoveHwndToWcvMapEntry(WebContentsViewWin* wcv) { | 44 void RemoveHwndToWcvMapEntry(WebContentsViewWin* wcv) { |
81 HwndToWcvMap::iterator it; | 45 HwndToWcvMap::iterator it; |
82 for (it = hwnd_to_wcv_map.begin(); it != hwnd_to_wcv_map.end();) { | 46 for (it = hwnd_to_wcv_map.begin(); it != hwnd_to_wcv_map.end();) { |
83 if (it->second == wcv) | 47 if (it->second == wcv) |
84 hwnd_to_wcv_map.erase(it++); | 48 hwnd_to_wcv_map.erase(it++); |
85 else | 49 else |
86 ++it; | 50 ++it; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 108 |
145 if (IsWindow(hwnd())) | 109 if (IsWindow(hwnd())) |
146 DestroyWindow(hwnd()); | 110 DestroyWindow(hwnd()); |
147 } | 111 } |
148 | 112 |
149 void WebContentsViewWin::CreateView(const gfx::Size& initial_size) { | 113 void WebContentsViewWin::CreateView(const gfx::Size& initial_size) { |
150 initial_size_ = initial_size; | 114 initial_size_ = initial_size; |
151 | 115 |
152 set_window_style(WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); | 116 set_window_style(WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); |
153 | 117 |
154 Init(TempParent::Get()->hwnd(), gfx::Rect(initial_size_)); | 118 Init(ui::GetHiddenWindow(), gfx::Rect(initial_size_)); |
155 | 119 |
156 // Remove the root view drop target so we can register our own. | 120 // Remove the root view drop target so we can register our own. |
157 RevokeDragDrop(GetNativeView()); | 121 RevokeDragDrop(GetNativeView()); |
158 drag_dest_ = new WebDragDest(hwnd(), web_contents_); | 122 drag_dest_ = new WebDragDest(hwnd(), web_contents_); |
159 if (delegate_.get()) { | 123 if (delegate_.get()) { |
160 content::WebDragDestDelegate* delegate = delegate_->GetDragDestDelegate(); | 124 content::WebDragDestDelegate* delegate = delegate_->GetDragDestDelegate(); |
161 if (delegate) | 125 if (delegate) |
162 drag_dest_->set_delegate(delegate); | 126 drag_dest_->set_delegate(delegate); |
163 } | 127 } |
164 } | 128 } |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 si.nMin = 1; | 487 si.nMin = 1; |
524 si.nMax = 100; | 488 si.nMax = 100; |
525 si.nPage = 10; | 489 si.nPage = 10; |
526 si.nPos = 50; | 490 si.nPos = 50; |
527 | 491 |
528 ::SetScrollInfo(hwnd(), SB_HORZ, &si, FALSE); | 492 ::SetScrollInfo(hwnd(), SB_HORZ, &si, FALSE); |
529 ::SetScrollInfo(hwnd(), SB_VERT, &si, FALSE); | 493 ::SetScrollInfo(hwnd(), SB_VERT, &si, FALSE); |
530 | 494 |
531 return 1; | 495 return 1; |
532 } | 496 } |
OLD | NEW |