1// Copyright (c) 2011 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 "chrome/browser/ui/views/constrained_window_views.h"
6
7#include "views/window/window_win.h"
8
9namespace {
10bool IsNonClientHitTestCode(UINT hittest) {
11  return hittest != HTCLIENT && hittest != HTNOWHERE && hittest != HTCLOSE;
12}
13}
14
15class NativeConstrainedWindowWin : public NativeConstrainedWindow,
16                                   public views::WindowWin {
17 public:
18  NativeConstrainedWindowWin(NativeConstrainedWindowDelegate* delegate,
19                             views::WindowDelegate* window_delegate)
20      : WindowWin(window_delegate),
21        delegate_(delegate) {
22    views::Widget::CreateParams params(
23        views::Widget::CreateParams::TYPE_WINDOW);
24    params.child = true;
25    SetCreateParams(params);
26  }
27
28  virtual ~NativeConstrainedWindowWin() {
29  }
30
31 private:
32  // Overridden from NativeConstrainedWindow:
33  virtual void InitNativeConstrainedWindow(gfx::NativeView parent) OVERRIDE {
34    WindowWin::Init(parent, gfx::Rect());
35  }
36  virtual views::NativeWindow* AsNativeWindow() OVERRIDE {
37    return this;
38  }
39
40  // Overridden from views::WindowWin:
41  virtual void OnFinalMessage(HWND window) OVERRIDE {
42    delegate_->OnNativeConstrainedWindowDestroyed();
43    WindowWin::OnFinalMessage(window);
44  }
45  virtual LRESULT OnMouseActivate(UINT message,
46                                  WPARAM w_param,
47                                  LPARAM l_param) OVERRIDE {
48    if (IsNonClientHitTestCode(static_cast<UINT>(LOWORD(l_param))))
49      delegate_->OnNativeConstrainedWindowMouseActivate();
50    return WindowWin::OnMouseActivate(message, w_param, l_param);
51  }
52
53  // Overridden from views::Window:
54  virtual views::NonClientFrameView* CreateFrameViewForWindow() OVERRIDE {
55    return delegate_->CreateFrameViewForWindow();
56  }
57
58  NativeConstrainedWindowDelegate* delegate_;
59
60  DISALLOW_COPY_AND_ASSIGN(NativeConstrainedWindowWin);
61};
62
63////////////////////////////////////////////////////////////////////////////////
64// NativeConstrainedWindow, public:
65
66// static
67NativeConstrainedWindow* NativeConstrainedWindow::CreateNativeConstrainedWindow(
68    NativeConstrainedWindowDelegate* delegate,
69    views::WindowDelegate* window_delegate) {
70  return new NativeConstrainedWindowWin(delegate, window_delegate);
71}
72