1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CONSTRAINED_WINDOW_IMPL_H_
#define CHROME_BROWSER_CONSTRAINED_WINDOW_IMPL_H_
#include "base/gfx/rect.h"
#include "chrome/browser/constrained_window.h"
#include "chrome/browser/tab_contents_delegate.h"
#include "chrome/views/custom_frame_window.h"
class ConstrainedTabContentsWindowDelegate;
class ConstrainedWindowAnimation;
class ConstrainedWindowNonClientView;
namespace ChromeViews {
class HWNDView;
class WindowDelegate;
}
///////////////////////////////////////////////////////////////////////////////
// ConstrainedWindowImpl
//
// A ConstrainedWindow implementation that implements a Constrained Window as
// a child HWND with a custom window frame.
//
class ConstrainedWindowImpl : public ConstrainedWindow,
public ChromeViews::CustomFrameWindow,
public TabContentsDelegate {
public:
virtual ~ConstrainedWindowImpl();
// Returns the TabContents that constrains this Constrained Window.
TabContents* owner() const { return owner_; }
TabContents* constrained_contents() const { return constrained_contents_; }
// Returns the non-client view inside this Constrained Window.
// NOTE: Defining the function body here would require pulling in the
// declarations of ConstrainedWindowNonClientView, as well as all the classes
// it depends on, from the .cc file; the benefit isn't worth it.
ConstrainedWindowNonClientView* non_client_view();
// Overridden from ConstrainedWindow:
virtual void CloseConstrainedWindow();
virtual void ActivateConstrainedWindow();
virtual void RepositionConstrainedWindowTo(const gfx::Point& anchor_point);
virtual bool IsSuppressedConstrainedWindow() const;
virtual void WasHidden();
virtual void DidBecomeSelected();
virtual std::wstring GetWindowTitle() const;
virtual void UpdateWindowTitle();
virtual const gfx::Rect& GetCurrentBounds() const;
// Overridden from PageNavigator (TabContentsDelegate's base interface):
virtual void OpenURLFromTab(TabContents* source,
const GURL& url,
WindowOpenDisposition disposition,
PageTransition::Type transition);
// Overridden from TabContentsDelegate:
virtual void NavigationStateChanged(const TabContents* source,
unsigned changed_flags);
virtual void ReplaceContents(TabContents* source,
TabContents* new_contents);
virtual void AddNewContents(TabContents* source,
TabContents* new_contents,
WindowOpenDisposition disposition,
const gfx::Rect& initial_pos,
bool user_gesture);
virtual void ActivateContents(TabContents* contents);
virtual void LoadingStateChanged(TabContents* source);
virtual void CloseContents(TabContents* source);
virtual void MoveContents(TabContents* source, const gfx::Rect& pos);
virtual bool IsPopup(TabContents* source);
virtual TabContents* GetConstrainingContents(TabContents* source);
virtual void ToolbarSizeChanged(TabContents* source, bool is_animating);
virtual void URLStarredChanged(TabContents* source, bool) {}
virtual void UpdateTargetURL(TabContents* source, const GURL& url) {}
virtual bool CanBlur() const { return false; }
virtual void NavigateToPage(TabContents* source, const GURL& url,
PageTransition::Type transition);
bool is_dialog() { return is_dialog_; }
// Changes the visibility of the titlebar. |percentage| is a real
// number ranged 0,1.
void SetTitlebarVisibilityPercentage(double percentage);
// Starts a ConstrainedWindowAnimation to slide in the titlebar of
// this suppressed constrained popup window.
void StartSuppressedAnimation();
// Stops the ConstrainedWindowAnimation, making the entire titlebar visible.
void StopSuppressedAnimationIfRunning();
protected:
// Windows message handlers:
virtual void OnDestroy();
virtual void OnFinalMessage(HWND window);
virtual void OnGetMinMaxInfo(LPMINMAXINFO mm_info);
virtual LRESULT OnMouseActivate(HWND window, UINT hittest_code, UINT message);
virtual void OnWindowPosChanged(WINDOWPOS* window_pos);
private:
friend class ConstrainedWindow;
// Use the static factory methods on ConstrainedWindow to construct a
// ConstrainedWindow.
ConstrainedWindowImpl(TabContents* owner,
ChromeViews::WindowDelegate* window_delegate,
TabContents* constrained_contents);
ConstrainedWindowImpl(TabContents* owner,
ChromeViews::WindowDelegate* window_delegate);
void Init(TabContents* owner);
// Called after changing either the anchor point or titlebar
// visibility of a suppressed popup.
//
// @see RepositionConstrainedWindowTo
// @see SetTitlebarVisibilityPercentage
void ResizeConstrainedTitlebar();
// Called to change the size of a constrained window. Moves the
// window to the anchor point (taking titlebar visibility into
// account) and sets the pop up size.
void ResizeConstrainedWindow(int width, int height);
// Initialize the Constrained Window as a Constrained Dialog containing a
// ChromeViews::View client area.
void InitAsDialog(const gfx::Rect& initial_bounds);
// Builds the underlying HWND and window delegates for a newly
// created popup window.
//
// We have to split the initialization process for a popup window in
// two because we first need to initialize a proper window delegate
// so that when we query for desired size, we get accurate data. If
// we didn't do this, windows will initialize to being smaller then
// the desired content size plus room for browser chrome.
void InitWindowForContents(TabContents* constrained_contents,
ConstrainedTabContentsWindowDelegate* delegate);
// Sets the initial bounds for a newly created popup window.
//
// This is the second part of the initialization process started
// with InitWindowForContents. For the parameter initial_bounds to
// have been calculated correctly, InitWindowForContents must have
// been run first.
void InitSizeForContents(const gfx::Rect& initial_bounds);
// Returns true if the Constrained Window can be detached from its owner.
bool CanDetach() const;
// Detach the Constrained TabContents from its owner.
void Detach();
// Updates the portions of the UI as specified in |changed_flags|.
void UpdateUI(unsigned int changed_flags);
// Place and size the window, constraining to the bounds of the |owner_|.
void SetWindowBounds(const gfx::Rect& bounds);
// The TabContents that owns and constrains this ConstrainedWindow.
TabContents* owner_;
// The TabContents constrained by |owner_|.
TabContents* constrained_contents_;
// True if focus should not be restored to whatever view was focused last
// when this window is destroyed.
bool focus_restoration_disabled_;
// A default ChromeViews::WindowDelegate implementation for this window when
// a TabContents is being constrained. (For the Constrained Dialog case, the
// caller is required to provide the WindowDelegate).
scoped_ptr<ChromeViews::WindowDelegate> contents_window_delegate_;
// We keep a reference on the HWNDView so we can properly detach the tab
// contents when detaching.
ChromeViews::HWNDView* contents_container_;
// true if this window is really a constrained dialog. This is set by
// InitAsDialog().
bool is_dialog_;
// Current "anchor point", the lower right point at which we render
// the constrained title bar.
gfx::Point anchor_point_;
// The 0,1 percentage representing what amount of a titlebar of a
// suppressed popup window should be visible. Used to animate those
// titlebars in.
double titlebar_visibility_;
// The animation class which animates constrained windows onto the page.
scoped_ptr<ConstrainedWindowAnimation> animation_;
// Current display rectangle (relative to owner_'s visible area).
gfx::Rect current_bounds_;
DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowImpl);
};
#endif // #ifndef CHROME_BROWSER_CONSTRAINED_WINDOW_IMPL_H_
|