| Index: views/controls/native/native_view_host_win.cc
|
| ===================================================================
|
| --- views/controls/native/native_view_host_win.cc (revision 0)
|
| +++ views/controls/native/native_view_host_win.cc (working copy)
|
| @@ -2,137 +2,134 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "views/controls/hwnd_view.h"
|
| +#include "views/controls/native/native_view_host_win.h"
|
|
|
| #include "app/gfx/canvas.h"
|
| #include "base/logging.h"
|
| +#include "views/controls/native/native_view_host.h"
|
| #include "views/focus/focus_manager.h"
|
| #include "views/widget/widget.h"
|
|
|
| namespace views {
|
|
|
| -static const char kViewClassName[] = "views/HWNDView";
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// NativeViewHostWin, public:
|
|
|
| -HWNDView::HWNDView() : NativeViewHost() {
|
| +NativeViewHostWin::NativeViewHostWin(NativeViewHost* host)
|
| + : host_(host),
|
| + installed_clip_(false) {
|
| }
|
|
|
| -HWNDView::~HWNDView() {
|
| +NativeViewHostWin::~NativeViewHostWin() {
|
| }
|
|
|
| -void HWNDView::Attach(HWND hwnd) {
|
| - DCHECK(native_view() == NULL);
|
| - DCHECK(hwnd) << "Impossible detatched tab case; See crbug.com/6316";
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// NativeViewHostWin, NativeViewHostWrapper implementation:
|
|
|
| - set_native_view(hwnd);
|
| +void NativeViewHostWin::NativeViewAttached() {
|
| + DCHECK(host_->native_view())
|
| + << "Impossible detatched tab case; See crbug.com/6316";
|
|
|
| // First hide the new window. We don't want anything to draw (like sub-hwnd
|
| // borders), when we change the parent below.
|
| - ShowWindow(hwnd, SW_HIDE);
|
| + ShowWindow(host_->native_view(), SW_HIDE);
|
|
|
| // Need to set the HWND's parent before changing its size to avoid flashing.
|
| - ::SetParent(hwnd, GetWidget()->GetNativeView());
|
| - Layout();
|
| + SetParent(host_->native_view(), host_->GetWidget()->GetNativeView());
|
| + host_->Layout();
|
|
|
| // Register with the focus manager so the associated view is focused when the
|
| // native control gets the focus.
|
| - FocusManager::InstallFocusSubclass(
|
| - hwnd, associated_focus_view() ? associated_focus_view() : this);
|
| + View* focus_view = host_->focus_view() ? host_->focus_view() : host_;
|
| + FocusManager::InstallFocusSubclass(host_->native_view(), focus_view);
|
| }
|
|
|
| -void HWNDView::Detach() {
|
| - DCHECK(native_view());
|
| - FocusManager::UninstallFocusSubclass(native_view());
|
| - set_native_view(NULL);
|
| - set_installed_clip(false);
|
| +void NativeViewHostWin::NativeViewDetaching() {
|
| + DCHECK(host_->native_view());
|
| + FocusManager::UninstallFocusSubclass(host_->native_view());
|
| + installed_clip_ = false;
|
| }
|
|
|
| -void HWNDView::Paint(gfx::Canvas* canvas) {
|
| - // The area behind our window is black, so during a fast resize (where our
|
| - // content doesn't draw over the full size of our HWND, and the HWND
|
| - // background color doesn't show up), we need to cover that blackness with
|
| - // something so that fast resizes don't result in black flash.
|
| - //
|
| - // It would be nice if this used some approximation of the page's
|
| - // current background color.
|
| - if (installed_clip())
|
| - canvas->FillRectInt(SkColorSetRGB(255, 255, 255), 0, 0, width(), height());
|
| +void NativeViewHostWin::AddedToWidget() {
|
| + HWND parent_hwnd = GetParent(host_->native_view());
|
| + HWND widget_hwnd = host_->GetWidget()->GetNativeView();
|
| + if (parent_hwnd != widget_hwnd)
|
| + SetParent(host_->native_view(), widget_hwnd);
|
| + if (host_->IsVisibleInRootView())
|
| + ShowWindow(host_->native_view(), SW_SHOW);
|
| + else
|
| + ShowWindow(host_->native_view(), SW_HIDE);
|
| + host_->Layout();
|
| }
|
|
|
| -std::string HWNDView::GetClassName() const {
|
| - return kViewClassName;
|
| +void NativeViewHostWin::RemovedFromWidget() {
|
| + ShowWindow(host_->native_view(), SW_HIDE);
|
| + SetParent(host_->native_view(), NULL);
|
| }
|
|
|
| -void HWNDView::ViewHierarchyChanged(bool is_add, View *parent, View *child) {
|
| - if (!native_view())
|
| - return;
|
| -
|
| - Widget* widget = GetWidget();
|
| - if (is_add && widget) {
|
| - HWND parent_hwnd = ::GetParent(native_view());
|
| - HWND widget_hwnd = widget->GetNativeView();
|
| - if (parent_hwnd != widget_hwnd)
|
| - ::SetParent(native_view(), widget_hwnd);
|
| - if (IsVisibleInRootView())
|
| - ::ShowWindow(native_view(), SW_SHOW);
|
| - else
|
| - ::ShowWindow(native_view(), SW_HIDE);
|
| - Layout();
|
| - } else if (!is_add) {
|
| - ::ShowWindow(native_view(), SW_HIDE);
|
| - ::SetParent(native_view(), NULL);
|
| - }
|
| -}
|
| -
|
| -void HWNDView::Focus() {
|
| - ::SetFocus(native_view());
|
| -}
|
| -
|
| -void HWNDView::InstallClip(int x, int y, int w, int h) {
|
| +void NativeViewHostWin::InstallClip(int x, int y, int w, int h) {
|
| HRGN clip_region = CreateRectRgn(x, y, x + w, y + h);
|
| // NOTE: SetWindowRgn owns the region (as well as the deleting the
|
| // current region), as such we don't delete the old region.
|
| - SetWindowRgn(native_view(), clip_region, FALSE);
|
| + SetWindowRgn(host_->native_view(), clip_region, FALSE);
|
| + installed_clip_ = true;
|
| }
|
|
|
| -void HWNDView::UninstallClip() {
|
| - SetWindowRgn(native_view(), 0, FALSE);
|
| +bool NativeViewHostWin::HasInstalledClip() {
|
| + return installed_clip_;
|
| }
|
|
|
| -void HWNDView::ShowWidget(int x, int y, int w, int h) {
|
| +void NativeViewHostWin::UninstallClip() {
|
| + SetWindowRgn(host_->native_view(), 0, FALSE);
|
| + installed_clip_ = false;
|
| +}
|
| +
|
| +void NativeViewHostWin::ShowWidget(int x, int y, int w, int h) {
|
| UINT swp_flags = SWP_DEFERERASE |
|
| SWP_NOACTIVATE |
|
| SWP_NOCOPYBITS |
|
| SWP_NOOWNERZORDER |
|
| SWP_NOZORDER;
|
| // Only send the SHOWWINDOW flag if we're invisible, to avoid flashing.
|
| - if (!::IsWindowVisible(native_view()))
|
| + if (!IsWindowVisible(host_->native_view()))
|
| swp_flags = (swp_flags | SWP_SHOWWINDOW) & ~SWP_NOREDRAW;
|
|
|
| - if (fast_resize()) {
|
| + if (host_->fast_resize()) {
|
| // In a fast resize, we move the window and clip it with SetWindowRgn.
|
| RECT win_rect;
|
| - GetWindowRect(native_view(), &win_rect);
|
| + GetWindowRect(host_->native_view(), &win_rect);
|
| gfx::Rect rect(win_rect);
|
| - ::SetWindowPos(native_view(), 0, x, y, rect.width(), rect.height(),
|
| - swp_flags);
|
| + SetWindowPos(host_->native_view(), 0, x, y, rect.width(), rect.height(),
|
| + swp_flags);
|
|
|
| - HRGN clip_region = CreateRectRgn(0, 0, w, h);
|
| - SetWindowRgn(native_view(), clip_region, FALSE);
|
| - set_installed_clip(true);
|
| + InstallClip(0, 0, w, h);
|
| } else {
|
| - ::SetWindowPos(native_view(), 0, x, y, w, h, swp_flags);
|
| + SetWindowPos(host_->native_view(), 0, x, y, w, h, swp_flags);
|
| }
|
| }
|
|
|
| -void HWNDView::HideWidget() {
|
| - if (!::IsWindowVisible(native_view()))
|
| +void NativeViewHostWin::HideWidget() {
|
| + if (!IsWindowVisible(host_->native_view()))
|
| return; // Currently not visible, nothing to do.
|
|
|
| // The window is currently visible, but its clipped by another view. Hide
|
| // it.
|
| - ::SetWindowPos(native_view(), 0, 0, 0, 0, 0,
|
| - SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
|
| - SWP_NOREDRAW | SWP_NOOWNERZORDER);
|
| + SetWindowPos(host_->native_view(), 0, 0, 0, 0, 0,
|
| + SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
|
| + SWP_NOREDRAW | SWP_NOOWNERZORDER);
|
| }
|
|
|
| +void NativeViewHostWin::SetFocus() {
|
| + ::SetFocus(host_->native_view());
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// NativeViewHostWrapper, public:
|
| +
|
| +// static
|
| +NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper(
|
| + NativeViewHost* host) {
|
| + return new NativeViewHostWin(host);
|
| +}
|
| +
|
| } // namespace views
|
|
|