Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: views/controls/hwnd_view.cc

Issue 114059: Refactors HWNDView, NativeViewHostGtk and NativeViewHost so that they match t... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/controls/hwnd_view.h ('k') | views/controls/native/native_view_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "views/controls/hwnd_view.h"
6
7 #include "app/gfx/canvas.h"
8 #include "base/logging.h"
9 #include "views/focus/focus_manager.h"
10 #include "views/widget/widget.h"
11
12 namespace views {
13
14 static const char kViewClassName[] = "views/HWNDView";
15
16 HWNDView::HWNDView() : NativeViewHost() {
17 }
18
19 HWNDView::~HWNDView() {
20 }
21
22 void HWNDView::Attach(HWND hwnd) {
23 DCHECK(native_view() == NULL);
24 DCHECK(hwnd) << "Impossible detatched tab case; See crbug.com/6316";
25
26 set_native_view(hwnd);
27
28 // First hide the new window. We don't want anything to draw (like sub-hwnd
29 // borders), when we change the parent below.
30 ShowWindow(hwnd, SW_HIDE);
31
32 // Need to set the HWND's parent before changing its size to avoid flashing.
33 ::SetParent(hwnd, GetWidget()->GetNativeView());
34 Layout();
35
36 // Register with the focus manager so the associated view is focused when the
37 // native control gets the focus.
38 FocusManager::InstallFocusSubclass(
39 hwnd, associated_focus_view() ? associated_focus_view() : this);
40 }
41
42 void HWNDView::Detach() {
43 DCHECK(native_view());
44 FocusManager::UninstallFocusSubclass(native_view());
45 set_native_view(NULL);
46 set_installed_clip(false);
47 }
48
49 void HWNDView::Paint(gfx::Canvas* canvas) {
50 // The area behind our window is black, so during a fast resize (where our
51 // content doesn't draw over the full size of our HWND, and the HWND
52 // background color doesn't show up), we need to cover that blackness with
53 // something so that fast resizes don't result in black flash.
54 //
55 // It would be nice if this used some approximation of the page's
56 // current background color.
57 if (installed_clip())
58 canvas->FillRectInt(SkColorSetRGB(255, 255, 255), 0, 0, width(), height());
59 }
60
61 std::string HWNDView::GetClassName() const {
62 return kViewClassName;
63 }
64
65 void HWNDView::ViewHierarchyChanged(bool is_add, View *parent, View *child) {
66 if (!native_view())
67 return;
68
69 Widget* widget = GetWidget();
70 if (is_add && widget) {
71 HWND parent_hwnd = ::GetParent(native_view());
72 HWND widget_hwnd = widget->GetNativeView();
73 if (parent_hwnd != widget_hwnd)
74 ::SetParent(native_view(), widget_hwnd);
75 if (IsVisibleInRootView())
76 ::ShowWindow(native_view(), SW_SHOW);
77 else
78 ::ShowWindow(native_view(), SW_HIDE);
79 Layout();
80 } else if (!is_add) {
81 ::ShowWindow(native_view(), SW_HIDE);
82 ::SetParent(native_view(), NULL);
83 }
84 }
85
86 void HWNDView::Focus() {
87 ::SetFocus(native_view());
88 }
89
90 void HWNDView::InstallClip(int x, int y, int w, int h) {
91 HRGN clip_region = CreateRectRgn(x, y, x + w, y + h);
92 // NOTE: SetWindowRgn owns the region (as well as the deleting the
93 // current region), as such we don't delete the old region.
94 SetWindowRgn(native_view(), clip_region, FALSE);
95 }
96
97 void HWNDView::UninstallClip() {
98 SetWindowRgn(native_view(), 0, FALSE);
99 }
100
101 void HWNDView::ShowWidget(int x, int y, int w, int h) {
102 UINT swp_flags = SWP_DEFERERASE |
103 SWP_NOACTIVATE |
104 SWP_NOCOPYBITS |
105 SWP_NOOWNERZORDER |
106 SWP_NOZORDER;
107 // Only send the SHOWWINDOW flag if we're invisible, to avoid flashing.
108 if (!::IsWindowVisible(native_view()))
109 swp_flags = (swp_flags | SWP_SHOWWINDOW) & ~SWP_NOREDRAW;
110
111 if (fast_resize()) {
112 // In a fast resize, we move the window and clip it with SetWindowRgn.
113 RECT win_rect;
114 GetWindowRect(native_view(), &win_rect);
115 gfx::Rect rect(win_rect);
116 ::SetWindowPos(native_view(), 0, x, y, rect.width(), rect.height(),
117 swp_flags);
118
119 HRGN clip_region = CreateRectRgn(0, 0, w, h);
120 SetWindowRgn(native_view(), clip_region, FALSE);
121 set_installed_clip(true);
122 } else {
123 ::SetWindowPos(native_view(), 0, x, y, w, h, swp_flags);
124 }
125 }
126
127 void HWNDView::HideWidget() {
128 if (!::IsWindowVisible(native_view()))
129 return; // Currently not visible, nothing to do.
130
131 // The window is currently visible, but its clipped by another view. Hide
132 // it.
133 ::SetWindowPos(native_view(), 0, 0, 0, 0, 0,
134 SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
135 SWP_NOREDRAW | SWP_NOOWNERZORDER);
136 }
137
138 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/hwnd_view.h ('k') | views/controls/native/native_view_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698