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 "chrome/browser/ui/views/panels/panel_view.h" | 5 #include "chrome/browser/ui/views/panels/panel_view.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 for (size_t i = 0; i < arraysize(kPanelAcceleratorMap); ++i) { | 91 for (size_t i = 0; i < arraysize(kPanelAcceleratorMap); ++i) { |
92 ui::Accelerator accelerator(kPanelAcceleratorMap[i].keycode, | 92 ui::Accelerator accelerator(kPanelAcceleratorMap[i].keycode, |
93 kPanelAcceleratorMap[i].modifiers); | 93 kPanelAcceleratorMap[i].modifiers); |
94 (*accelerators)[accelerator] = kPanelAcceleratorMap[i].command_id; | 94 (*accelerators)[accelerator] = kPanelAcceleratorMap[i].command_id; |
95 } | 95 } |
96 } | 96 } |
97 return *accelerators; | 97 return *accelerators; |
98 } | 98 } |
99 | 99 |
100 // NativePanelTesting implementation. | 100 // NativePanelTesting implementation. |
101 class NativePanelTestingWin : public NativePanelTesting { | 101 class NativePanelTestingViews : public NativePanelTesting { |
102 public: | 102 public: |
103 explicit NativePanelTestingWin(PanelView* panel_view); | 103 explicit NativePanelTestingViews(PanelView* panel_view); |
| 104 virtual ~NativePanelTestingViews(); |
104 | 105 |
105 private: | 106 private: |
106 virtual void PressLeftMouseButtonTitlebar( | 107 virtual void PressLeftMouseButtonTitlebar( |
107 const gfx::Point& mouse_location, panel::ClickModifier modifier) OVERRIDE; | 108 const gfx::Point& mouse_location, panel::ClickModifier modifier) OVERRIDE; |
108 virtual void ReleaseMouseButtonTitlebar( | 109 virtual void ReleaseMouseButtonTitlebar( |
109 panel::ClickModifier modifier) OVERRIDE; | 110 panel::ClickModifier modifier) OVERRIDE; |
110 virtual void DragTitlebar(const gfx::Point& mouse_location) OVERRIDE; | 111 virtual void DragTitlebar(const gfx::Point& mouse_location) OVERRIDE; |
111 virtual void CancelDragTitlebar() OVERRIDE; | 112 virtual void CancelDragTitlebar() OVERRIDE; |
112 virtual void FinishDragTitlebar() OVERRIDE; | 113 virtual void FinishDragTitlebar() OVERRIDE; |
113 virtual bool VerifyDrawingAttention() const OVERRIDE; | 114 virtual bool VerifyDrawingAttention() const OVERRIDE; |
114 virtual bool VerifyActiveState(bool is_active) OVERRIDE; | 115 virtual bool VerifyActiveState(bool is_active) OVERRIDE; |
115 virtual bool VerifyAppIcon() const OVERRIDE; | 116 virtual bool VerifyAppIcon() const OVERRIDE; |
116 virtual bool VerifySystemMinimizeState() const OVERRIDE; | 117 virtual bool VerifySystemMinimizeState() const OVERRIDE; |
117 virtual bool IsWindowVisible() const OVERRIDE; | 118 virtual bool IsWindowVisible() const OVERRIDE; |
118 virtual bool IsWindowSizeKnown() const OVERRIDE; | 119 virtual bool IsWindowSizeKnown() const OVERRIDE; |
119 virtual bool IsAnimatingBounds() const OVERRIDE; | 120 virtual bool IsAnimatingBounds() const OVERRIDE; |
120 virtual bool IsButtonVisible( | 121 virtual bool IsButtonVisible( |
121 panel::TitlebarButtonType button_type) const OVERRIDE; | 122 panel::TitlebarButtonType button_type) const OVERRIDE; |
122 virtual panel::CornerStyle GetWindowCornerStyle() const OVERRIDE; | 123 virtual panel::CornerStyle GetWindowCornerStyle() const OVERRIDE; |
123 virtual bool EnsureApplicationRunOnForeground() OVERRIDE; | 124 virtual bool EnsureApplicationRunOnForeground() OVERRIDE; |
124 | 125 |
125 PanelView* panel_view_; | 126 PanelView* panel_view_; |
126 }; | 127 }; |
127 | 128 |
128 NativePanelTestingWin::NativePanelTestingWin(PanelView* panel_view) | 129 NativePanelTestingViews::NativePanelTestingViews(PanelView* panel_view) |
129 : panel_view_(panel_view) { | 130 : panel_view_(panel_view) { |
130 } | 131 } |
131 | 132 |
132 void NativePanelTestingWin::PressLeftMouseButtonTitlebar( | 133 NativePanelTestingViews::~NativePanelTestingViews() { |
| 134 } |
| 135 |
| 136 void NativePanelTestingViews::PressLeftMouseButtonTitlebar( |
133 const gfx::Point& mouse_location, panel::ClickModifier modifier) { | 137 const gfx::Point& mouse_location, panel::ClickModifier modifier) { |
134 panel_view_->OnTitlebarMousePressed(mouse_location); | 138 panel_view_->OnTitlebarMousePressed(mouse_location); |
135 } | 139 } |
136 | 140 |
137 void NativePanelTestingWin::ReleaseMouseButtonTitlebar( | 141 void NativePanelTestingViews::ReleaseMouseButtonTitlebar( |
138 panel::ClickModifier modifier) { | 142 panel::ClickModifier modifier) { |
139 panel_view_->OnTitlebarMouseReleased(modifier); | 143 panel_view_->OnTitlebarMouseReleased(modifier); |
140 } | 144 } |
141 | 145 |
142 void NativePanelTestingWin::DragTitlebar(const gfx::Point& mouse_location) { | 146 void NativePanelTestingViews::DragTitlebar(const gfx::Point& mouse_location) { |
143 panel_view_->OnTitlebarMouseDragged(mouse_location); | 147 panel_view_->OnTitlebarMouseDragged(mouse_location); |
144 } | 148 } |
145 | 149 |
146 void NativePanelTestingWin::CancelDragTitlebar() { | 150 void NativePanelTestingViews::CancelDragTitlebar() { |
147 panel_view_->OnTitlebarMouseCaptureLost(); | 151 panel_view_->OnTitlebarMouseCaptureLost(); |
148 } | 152 } |
149 | 153 |
150 void NativePanelTestingWin::FinishDragTitlebar() { | 154 void NativePanelTestingViews::FinishDragTitlebar() { |
151 panel_view_->OnTitlebarMouseReleased(panel::NO_MODIFIER); | 155 panel_view_->OnTitlebarMouseReleased(panel::NO_MODIFIER); |
152 } | 156 } |
153 | 157 |
154 bool NativePanelTestingWin::VerifyDrawingAttention() const { | 158 bool NativePanelTestingViews::VerifyDrawingAttention() const { |
155 base::MessageLoop::current()->RunUntilIdle(); | 159 base::MessageLoop::current()->RunUntilIdle(); |
156 return panel_view_->GetFrameView()->GetPaintState() == | 160 return panel_view_->GetFrameView()->GetPaintState() == |
157 PanelFrameView::PAINT_FOR_ATTENTION; | 161 PanelFrameView::PAINT_FOR_ATTENTION; |
158 } | 162 } |
159 | 163 |
160 bool NativePanelTestingWin::VerifyActiveState(bool is_active) { | 164 bool NativePanelTestingViews::VerifyActiveState(bool is_active) { |
161 return panel_view_->GetFrameView()->GetPaintState() == | 165 return panel_view_->GetFrameView()->GetPaintState() == |
162 (is_active ? PanelFrameView::PAINT_AS_ACTIVE | 166 (is_active ? PanelFrameView::PAINT_AS_ACTIVE |
163 : PanelFrameView::PAINT_AS_INACTIVE); | 167 : PanelFrameView::PAINT_AS_INACTIVE); |
164 } | 168 } |
165 | 169 |
166 bool NativePanelTestingWin::VerifyAppIcon() const { | 170 bool NativePanelTestingViews::VerifyAppIcon() const { |
167 #if defined(OS_WIN) | 171 #if defined(OS_WIN) |
168 // We only care about Windows 7 and later. | 172 // We only care about Windows 7 and later. |
169 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 173 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
170 return true; | 174 return true; |
171 | 175 |
172 HWND native_window = views::HWNDForWidget(panel_view_->window()); | 176 HWND native_window = views::HWNDForWidget(panel_view_->window()); |
173 HICON app_icon = reinterpret_cast<HICON>( | 177 HICON app_icon = reinterpret_cast<HICON>( |
174 ::SendMessage(native_window, WM_GETICON, ICON_BIG, 0L)); | 178 ::SendMessage(native_window, WM_GETICON, ICON_BIG, 0L)); |
175 if (!app_icon) | 179 if (!app_icon) |
176 return false; | 180 return false; |
177 scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(app_icon)); | 181 scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(app_icon)); |
178 return bitmap.get() && | 182 return bitmap.get() && |
179 bitmap->width() == panel::kPanelAppIconSize && | 183 bitmap->width() == panel::kPanelAppIconSize && |
180 bitmap->height() == panel::kPanelAppIconSize; | 184 bitmap->height() == panel::kPanelAppIconSize; |
181 #else | 185 #else |
182 return true; | 186 return true; |
183 #endif | 187 #endif |
184 } | 188 } |
185 | 189 |
186 bool NativePanelTestingWin::VerifySystemMinimizeState() const { | 190 bool NativePanelTestingViews::VerifySystemMinimizeState() const { |
187 #if defined(OS_WIN) | 191 #if defined(OS_WIN) |
188 HWND native_window = views::HWNDForWidget(panel_view_->window()); | 192 HWND native_window = views::HWNDForWidget(panel_view_->window()); |
189 WINDOWPLACEMENT placement; | 193 WINDOWPLACEMENT placement; |
190 if (!::GetWindowPlacement(native_window, &placement)) | 194 if (!::GetWindowPlacement(native_window, &placement)) |
191 return false; | 195 return false; |
192 if (placement.showCmd == SW_MINIMIZE || placement.showCmd == SW_SHOWMINIMIZED) | 196 if (placement.showCmd == SW_MINIMIZE || placement.showCmd == SW_SHOWMINIMIZED) |
193 return true; | 197 return true; |
194 | 198 |
195 // If the panel window has owner window, as in stacked mode, check its owner | 199 // If the panel window has owner window, as in stacked mode, check its owner |
196 // window. Note that owner window, instead of parent window, is returned | 200 // window. Note that owner window, instead of parent window, is returned |
197 // though GWL_HWNDPARENT contains 'parent'. | 201 // though GWL_HWNDPARENT contains 'parent'. |
198 HWND owner_window = | 202 HWND owner_window = |
199 reinterpret_cast<HWND>(::GetWindowLongPtr(native_window, | 203 reinterpret_cast<HWND>(::GetWindowLongPtr(native_window, |
200 GWLP_HWNDPARENT)); | 204 GWLP_HWNDPARENT)); |
201 if (!owner_window || !::GetWindowPlacement(owner_window, &placement)) | 205 if (!owner_window || !::GetWindowPlacement(owner_window, &placement)) |
202 return false; | 206 return false; |
203 return placement.showCmd == SW_MINIMIZE || | 207 return placement.showCmd == SW_MINIMIZE || |
204 placement.showCmd == SW_SHOWMINIMIZED; | 208 placement.showCmd == SW_SHOWMINIMIZED; |
205 #else | 209 #else |
206 return true; | 210 return true; |
207 #endif | 211 #endif |
208 } | 212 } |
209 | 213 |
210 bool NativePanelTestingWin::IsWindowVisible() const { | 214 bool NativePanelTestingViews::IsWindowVisible() const { |
211 #if defined(OS_WIN) | 215 return panel_view_->window()->IsVisible(); |
212 HWND native_window = views::HWNDForWidget(panel_view_->window()); | |
213 return ::IsWindowVisible(native_window) == TRUE; | |
214 #else | |
215 return panel_view_->visible(); | |
216 #endif | |
217 } | 216 } |
218 | 217 |
219 bool NativePanelTestingWin::IsWindowSizeKnown() const { | 218 bool NativePanelTestingViews::IsWindowSizeKnown() const { |
220 return true; | 219 return true; |
221 } | 220 } |
222 | 221 |
223 bool NativePanelTestingWin::IsAnimatingBounds() const { | 222 bool NativePanelTestingViews::IsAnimatingBounds() const { |
224 return panel_view_->IsAnimatingBounds(); | 223 return panel_view_->IsAnimatingBounds(); |
225 } | 224 } |
226 | 225 |
227 bool NativePanelTestingWin::IsButtonVisible( | 226 bool NativePanelTestingViews::IsButtonVisible( |
228 panel::TitlebarButtonType button_type) const { | 227 panel::TitlebarButtonType button_type) const { |
229 PanelFrameView* frame_view = panel_view_->GetFrameView(); | 228 PanelFrameView* frame_view = panel_view_->GetFrameView(); |
230 | 229 |
231 switch (button_type) { | 230 switch (button_type) { |
232 case panel::CLOSE_BUTTON: | 231 case panel::CLOSE_BUTTON: |
233 return frame_view->close_button()->visible(); | 232 return frame_view->close_button()->visible(); |
234 case panel::MINIMIZE_BUTTON: | 233 case panel::MINIMIZE_BUTTON: |
235 return frame_view->minimize_button()->visible(); | 234 return frame_view->minimize_button()->visible(); |
236 case panel::RESTORE_BUTTON: | 235 case panel::RESTORE_BUTTON: |
237 return frame_view->restore_button()->visible(); | 236 return frame_view->restore_button()->visible(); |
238 default: | 237 default: |
239 NOTREACHED(); | 238 NOTREACHED(); |
240 } | 239 } |
241 return false; | 240 return false; |
242 } | 241 } |
243 | 242 |
244 panel::CornerStyle NativePanelTestingWin::GetWindowCornerStyle() const { | 243 panel::CornerStyle NativePanelTestingViews::GetWindowCornerStyle() const { |
245 return panel_view_->GetFrameView()->corner_style(); | 244 return panel_view_->GetFrameView()->corner_style(); |
246 } | 245 } |
247 | 246 |
248 bool NativePanelTestingWin::EnsureApplicationRunOnForeground() { | 247 bool NativePanelTestingViews::EnsureApplicationRunOnForeground() { |
249 // Not needed on views. | 248 // Not needed on views. |
250 return true; | 249 return true; |
251 } | 250 } |
252 | 251 |
253 } // namespace | 252 } // namespace |
254 | 253 |
255 // static | 254 // static |
256 NativePanel* Panel::CreateNativePanel(Panel* panel, | 255 NativePanel* Panel::CreateNativePanel(Panel* panel, |
257 const gfx::Rect& bounds, | 256 const gfx::Rect& bounds, |
258 bool always_on_top) { | 257 bool always_on_top) { |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 | 745 |
747 void PanelView::AttachWebContents(content::WebContents* contents) { | 746 void PanelView::AttachWebContents(content::WebContents* contents) { |
748 web_view_->SetWebContents(contents); | 747 web_view_->SetWebContents(contents); |
749 } | 748 } |
750 | 749 |
751 void PanelView::DetachWebContents(content::WebContents* contents) { | 750 void PanelView::DetachWebContents(content::WebContents* contents) { |
752 web_view_->SetWebContents(NULL); | 751 web_view_->SetWebContents(NULL); |
753 } | 752 } |
754 | 753 |
755 NativePanelTesting* PanelView::CreateNativePanelTesting() { | 754 NativePanelTesting* PanelView::CreateNativePanelTesting() { |
756 return new NativePanelTestingWin(this); | 755 return new NativePanelTestingViews(this); |
757 } | 756 } |
758 | 757 |
759 void PanelView::OnDisplayChanged() { | 758 void PanelView::OnDisplayChanged() { |
760 panel_->manager()->display_settings_provider()->OnDisplaySettingsChanged(); | 759 panel_->manager()->display_settings_provider()->OnDisplaySettingsChanged(); |
761 } | 760 } |
762 | 761 |
763 void PanelView::OnWorkAreaChanged() { | 762 void PanelView::OnWorkAreaChanged() { |
764 panel_->manager()->display_settings_provider()->OnDisplaySettingsChanged(); | 763 panel_->manager()->display_settings_provider()->OnDisplaySettingsChanged(); |
765 } | 764 } |
766 | 765 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 return; | 984 return; |
986 | 985 |
987 bool focused = active; | 986 bool focused = active; |
988 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_NATIVE) { | 987 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_NATIVE) { |
989 // The panel window is in focus (actually accepting keystrokes) if it is | 988 // The panel window is in focus (actually accepting keystrokes) if it is |
990 // active and belongs to a foreground application. | 989 // active and belongs to a foreground application. |
991 focused = active && | 990 focused = active && |
992 views::HWNDForWidget(widget) == ::GetForegroundWindow(); | 991 views::HWNDForWidget(widget) == ::GetForegroundWindow(); |
993 } | 992 } |
994 #else | 993 #else |
995 NOTIMPLEMENTED(); | |
996 bool focused = active; | 994 bool focused = active; |
997 #endif | 995 #endif |
998 | 996 |
999 if (focused_ == focused) | 997 if (focused_ == focused) |
1000 return; | 998 return; |
1001 focused_ = focused; | 999 focused_ = focused; |
1002 | 1000 |
1003 // Expand the panel if the minimized panel is activated by means other than | 1001 // Expand the panel if the minimized panel is activated by means other than |
1004 // clicking on its titlebar. This is the workaround to support restoring the | 1002 // clicking on its titlebar. This is the workaround to support restoring the |
1005 // minimized panel by other means, like alt-tabbing, win-tabbing, or clicking | 1003 // minimized panel by other means, like alt-tabbing, win-tabbing, or clicking |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1152 // SWP_FRAMECHANGED flag must be called in order for the cached window data | 1150 // SWP_FRAMECHANGED flag must be called in order for the cached window data |
1153 // to be updated properly. | 1151 // to be updated properly. |
1154 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms633591(v=vs.85).a
spx | 1152 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms633591(v=vs.85).a
spx |
1155 if (update_frame) { | 1153 if (update_frame) { |
1156 ::SetWindowPos(native_window, NULL, 0, 0, 0, 0, | 1154 ::SetWindowPos(native_window, NULL, 0, 0, 0, 0, |
1157 SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | | 1155 SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | |
1158 SWP_NOZORDER | SWP_NOACTIVATE); | 1156 SWP_NOZORDER | SWP_NOACTIVATE); |
1159 } | 1157 } |
1160 } | 1158 } |
1161 #endif | 1159 #endif |
OLD | NEW |