OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "views/widget/widget_win.h" | 5 #include "views/widget/widget_win.h" |
6 | 6 |
7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 Widget::Init(parent, bounds); | 204 Widget::Init(parent, bounds); |
205 | 205 |
206 // Create the window. | 206 // Create the window. |
207 WindowImpl::Init(parent, bounds); | 207 WindowImpl::Init(parent, bounds); |
208 } | 208 } |
209 | 209 |
210 void WidgetWin::InitWithWidget(Widget* parent, const gfx::Rect& bounds) { | 210 void WidgetWin::InitWithWidget(Widget* parent, const gfx::Rect& bounds) { |
211 Init(parent->GetNativeView(), bounds); | 211 Init(parent->GetNativeView(), bounds); |
212 } | 212 } |
213 | 213 |
| 214 gfx::NativeView WidgetWin::GetNativeView() const { |
| 215 return WindowImpl::hwnd(); |
| 216 } |
| 217 |
| 218 void WidgetWin::GenerateMousePressedForView(View* view, |
| 219 const gfx::Point& point) { |
| 220 gfx::Point point_in_widget(point); |
| 221 View::ConvertPointToWidget(view, &point_in_widget); |
| 222 GetRootView()->SetMouseHandler(view); |
| 223 ProcessMousePressed(point_in_widget.ToPOINT(), MK_LBUTTON, false, false); |
| 224 } |
| 225 |
| 226 bool WidgetWin::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) { |
| 227 return false; |
| 228 } |
| 229 |
| 230 Window* WidgetWin::GetWindow() { |
| 231 return GetWindowImpl(hwnd()); |
| 232 } |
| 233 |
| 234 const Window* WidgetWin::GetWindow() const { |
| 235 return GetWindowImpl(hwnd()); |
| 236 } |
| 237 |
| 238 void WidgetWin::ViewHierarchyChanged(bool is_add, View* parent, |
| 239 View* child) { |
| 240 Widget::ViewHierarchyChanged(is_add, parent, child); |
| 241 if (drop_target_.get()) |
| 242 drop_target_->ResetTargetViewIfEquals(child); |
| 243 |
| 244 if (!is_add) |
| 245 ClearAccessibilityViewEvent(child); |
| 246 } |
| 247 |
| 248 //////////////////////////////////////////////////////////////////////////////// |
| 249 // WidgetWin, NativeWidget implementation: |
| 250 |
| 251 Widget* WidgetWin::GetWidget() { |
| 252 return this; |
| 253 } |
| 254 |
| 255 void WidgetWin::SetNativeWindowProperty(const char* name, void* value) { |
| 256 // Remove the existing property (if any). |
| 257 for (ViewProps::iterator i = props_.begin(); i != props_.end(); ++i) { |
| 258 if ((*i)->Key() == name) { |
| 259 props_.erase(i); |
| 260 break; |
| 261 } |
| 262 } |
| 263 |
| 264 if (value) |
| 265 props_.push_back(new ViewProp(hwnd(), name, value)); |
| 266 } |
| 267 |
| 268 void* WidgetWin::GetNativeWindowProperty(const char* name) { |
| 269 return ViewProp::GetValue(hwnd(), name); |
| 270 } |
| 271 |
| 272 TooltipManager* WidgetWin::GetTooltipManager() const { |
| 273 return tooltip_manager_.get(); |
| 274 } |
| 275 |
| 276 gfx::Rect WidgetWin::GetWindowScreenBounds() const { |
| 277 RECT r; |
| 278 GetWindowRect(&r); |
| 279 return gfx::Rect(r); |
| 280 } |
| 281 |
| 282 gfx::Rect WidgetWin::GetClientAreaScreenBounds() const { |
| 283 RECT r; |
| 284 GetClientRect(&r); |
| 285 POINT point = { r.left, r.top }; |
| 286 ClientToScreen(hwnd(), &point); |
| 287 return gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top); |
| 288 } |
| 289 |
214 void WidgetWin::SetBounds(const gfx::Rect& bounds) { | 290 void WidgetWin::SetBounds(const gfx::Rect& bounds) { |
215 LONG style = GetWindowLong(GWL_STYLE); | 291 LONG style = GetWindowLong(GWL_STYLE); |
216 if (style & WS_MAXIMIZE) | 292 if (style & WS_MAXIMIZE) |
217 SetWindowLong(GWL_STYLE, style & ~WS_MAXIMIZE); | 293 SetWindowLong(GWL_STYLE, style & ~WS_MAXIMIZE); |
218 SetWindowPos(NULL, bounds.x(), bounds.y(), bounds.width(), bounds.height(), | 294 SetWindowPos(NULL, bounds.x(), bounds.y(), bounds.width(), bounds.height(), |
219 SWP_NOACTIVATE | SWP_NOZORDER); | 295 SWP_NOACTIVATE | SWP_NOZORDER); |
220 } | 296 } |
221 | 297 |
222 void WidgetWin::MoveAbove(Widget* other) { | 298 void WidgetWin::MoveAbove(Widget* other) { |
223 gfx::Rect bounds = GetClientAreaScreenBounds(); | 299 SetWindowPos(other->GetNativeView(), 0, 0, 0, 0, |
224 SetWindowPos(other->GetNativeView(), bounds.x(), bounds.y(), | 300 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); |
225 bounds.width(), bounds.height(), SWP_NOACTIVATE); | |
226 } | 301 } |
227 | 302 |
228 void WidgetWin::SetShape(gfx::NativeRegion region) { | 303 void WidgetWin::SetShape(gfx::NativeRegion region) { |
229 SetWindowRgn(region, TRUE); | 304 SetWindowRgn(region, TRUE); |
230 } | 305 } |
231 | 306 |
232 void WidgetWin::Close() { | 307 void WidgetWin::Close() { |
233 if (!IsWindow()) | 308 if (!IsWindow()) |
234 return; // No need to do anything. | 309 return; // No need to do anything. |
235 | 310 |
(...skipping 30 matching lines...) Expand all Loading... |
266 // NOTE: Be careful not to activate any windows here (for example, calling | 341 // NOTE: Be careful not to activate any windows here (for example, calling |
267 // ShowWindow(SW_HIDE) will automatically activate another window). This | 342 // ShowWindow(SW_HIDE) will automatically activate another window). This |
268 // code can be called while a window is being deactivated, and activating | 343 // code can be called while a window is being deactivated, and activating |
269 // another window will screw up the activation that is already in progress. | 344 // another window will screw up the activation that is already in progress. |
270 SetWindowPos(NULL, 0, 0, 0, 0, | 345 SetWindowPos(NULL, 0, 0, 0, 0, |
271 SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | | 346 SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | |
272 SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER); | 347 SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER); |
273 } | 348 } |
274 } | 349 } |
275 | 350 |
276 gfx::NativeView WidgetWin::GetNativeView() const { | |
277 return WindowImpl::hwnd(); | |
278 } | |
279 | |
280 void WidgetWin::SetOpacity(unsigned char opacity) { | 351 void WidgetWin::SetOpacity(unsigned char opacity) { |
281 layered_alpha_ = static_cast<BYTE>(opacity); | 352 layered_alpha_ = static_cast<BYTE>(opacity); |
282 } | 353 } |
283 | 354 |
284 void WidgetWin::SetAlwaysOnTop(bool on_top) { | 355 void WidgetWin::SetAlwaysOnTop(bool on_top) { |
285 if (on_top) | 356 if (on_top) |
286 set_window_ex_style(window_ex_style() | WS_EX_TOPMOST); | 357 set_window_ex_style(window_ex_style() | WS_EX_TOPMOST); |
287 else | 358 else |
288 set_window_ex_style(window_ex_style() & ~WS_EX_TOPMOST); | 359 set_window_ex_style(window_ex_style() & ~WS_EX_TOPMOST); |
289 } | 360 } |
290 | 361 |
291 bool WidgetWin::IsVisible() const { | 362 bool WidgetWin::IsVisible() const { |
292 return !!::IsWindowVisible(hwnd()); | 363 return !!::IsWindowVisible(hwnd()); |
293 } | 364 } |
294 | 365 |
295 bool WidgetWin::IsActive() const { | 366 bool WidgetWin::IsActive() const { |
296 return IsWindowActive(hwnd()); | 367 return IsWindowActive(hwnd()); |
297 } | 368 } |
298 | 369 |
299 bool WidgetWin::IsAccessibleWidget() const { | 370 bool WidgetWin::IsAccessibleWidget() const { |
300 return screen_reader_active_; | 371 return screen_reader_active_; |
301 } | 372 } |
302 | 373 |
303 void WidgetWin::GenerateMousePressedForView(View* view, | |
304 const gfx::Point& point) { | |
305 gfx::Point point_in_widget(point); | |
306 View::ConvertPointToWidget(view, &point_in_widget); | |
307 GetRootView()->SetMouseHandler(view); | |
308 ProcessMousePressed(point_in_widget.ToPOINT(), MK_LBUTTON, false, false); | |
309 } | |
310 | |
311 bool WidgetWin::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) { | |
312 return false; | |
313 } | |
314 | |
315 Window* WidgetWin::GetWindow() { | |
316 return GetWindowImpl(hwnd()); | |
317 } | |
318 | |
319 const Window* WidgetWin::GetWindow() const { | |
320 return GetWindowImpl(hwnd()); | |
321 } | |
322 | |
323 void WidgetWin::ViewHierarchyChanged(bool is_add, View* parent, | |
324 View* child) { | |
325 Widget::ViewHierarchyChanged(is_add, parent, child); | |
326 if (drop_target_.get()) | |
327 drop_target_->ResetTargetViewIfEquals(child); | |
328 | |
329 if (!is_add) | |
330 ClearAccessibilityViewEvent(child); | |
331 } | |
332 | |
333 //////////////////////////////////////////////////////////////////////////////// | |
334 // WidgetWin, NativeWidget implementation: | |
335 | |
336 Widget* WidgetWin::GetWidget() { | |
337 return this; | |
338 } | |
339 | |
340 void WidgetWin::SetNativeWindowProperty(const char* name, void* value) { | |
341 // Remove the existing property (if any). | |
342 for (ViewProps::iterator i = props_.begin(); i != props_.end(); ++i) { | |
343 if ((*i)->Key() == name) { | |
344 props_.erase(i); | |
345 break; | |
346 } | |
347 } | |
348 | |
349 if (value) | |
350 props_.push_back(new ViewProp(hwnd(), name, value)); | |
351 } | |
352 | |
353 void* WidgetWin::GetNativeWindowProperty(const char* name) { | |
354 return ViewProp::GetValue(hwnd(), name); | |
355 } | |
356 | |
357 TooltipManager* WidgetWin::GetTooltipManager() const { | |
358 return tooltip_manager_.get(); | |
359 } | |
360 | |
361 gfx::Rect WidgetWin::GetWindowScreenBounds() const { | |
362 RECT r; | |
363 GetWindowRect(&r); | |
364 return gfx::Rect(r); | |
365 } | |
366 | |
367 gfx::Rect WidgetWin::GetClientAreaScreenBounds() const { | |
368 RECT r; | |
369 GetClientRect(&r); | |
370 POINT point = { r.left, r.top }; | |
371 ClientToScreen(hwnd(), &point); | |
372 return gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top); | |
373 } | |
374 | |
375 bool WidgetWin::ContainsNativeView(gfx::NativeView native_view) const { | 374 bool WidgetWin::ContainsNativeView(gfx::NativeView native_view) const { |
376 if (hwnd() == native_view) | 375 if (hwnd() == native_view) |
377 return true; | 376 return true; |
378 | 377 |
379 // Traverse the set of parents of the given view to determine if native_view | 378 // Traverse the set of parents of the given view to determine if native_view |
380 // is a descendant of this window. | 379 // is a descendant of this window. |
381 HWND parent_window = ::GetParent(native_view); | 380 HWND parent_window = ::GetParent(native_view); |
382 HWND previous_child = native_view; | 381 HWND previous_child = native_view; |
383 while (parent_window && parent_window != previous_child) { | 382 while (parent_window && parent_window != previous_child) { |
384 if (hwnd() == parent_window) | 383 if (hwnd() == parent_window) |
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1241 return; | 1240 return; |
1242 | 1241 |
1243 NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view); | 1242 NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view); |
1244 if (native_widget) | 1243 if (native_widget) |
1245 children->insert(native_widget); | 1244 children->insert(native_widget); |
1246 EnumChildWindows(native_view, EnumerateChildWindowsForNativeWidgets, | 1245 EnumChildWindows(native_view, EnumerateChildWindowsForNativeWidgets, |
1247 reinterpret_cast<LPARAM>(children)); | 1246 reinterpret_cast<LPARAM>(children)); |
1248 } | 1247 } |
1249 | 1248 |
1250 } // namespace views | 1249 } // namespace views |
OLD | NEW |