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 "ui/views/widget/native_widget_aura.h" | 5 #include "ui/views/widget/native_widget_aura.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "third_party/skia/include/core/SkRegion.h" | 9 #include "third_party/skia/include/core/SkRegion.h" |
10 #include "ui/aura/client/activation_change_observer.h" | 10 #include "ui/aura/client/activation_change_observer.h" |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 // When centering window, we take the intersection of the host and | 352 // When centering window, we take the intersection of the host and |
353 // the parent. We assume the root window represents the visible | 353 // the parent. We assume the root window represents the visible |
354 // rect of a single screen. | 354 // rect of a single screen. |
355 gfx::Rect work_area = | 355 gfx::Rect work_area = |
356 gfx::Screen::GetDisplayNearestWindow(window_).work_area(); | 356 gfx::Screen::GetDisplayNearestWindow(window_).work_area(); |
357 | 357 |
358 aura::client::ScreenPositionClient* screen_position_client = | 358 aura::client::ScreenPositionClient* screen_position_client = |
359 aura::client::GetScreenPositionClient(window_->GetRootWindow()); | 359 aura::client::GetScreenPositionClient(window_->GetRootWindow()); |
360 if (screen_position_client) { | 360 if (screen_position_client) { |
361 gfx::Point origin = work_area.origin(); | 361 gfx::Point origin = work_area.origin(); |
362 screen_position_client->ConvertPointFromScreen(window_->parent(), | 362 screen_position_client->ConvertPointFromScreen(window_->GetRootWindow(), |
363 &origin); | 363 &origin); |
364 work_area.set_origin(origin); | 364 work_area.set_origin(origin); |
365 } | 365 } |
366 | 366 |
367 parent_bounds = parent_bounds.Intersect(work_area); | 367 parent_bounds = parent_bounds.Intersect(work_area); |
368 | 368 |
369 // If |window_|'s transient parent's bounds are big enough to fit it, then we | 369 // If |window_|'s transient parent's bounds are big enough to fit it, then we |
370 // center it with respect to the transient parent. | 370 // center it with respect to the transient parent. |
371 if (window_->transient_parent()) { | 371 if (window_->transient_parent()) { |
372 gfx::Rect transient_parent_rect = window_->transient_parent()-> | 372 gfx::Rect transient_parent_rect = window_->transient_parent()-> |
373 GetBoundsInRootWindow().Intersect(work_area); | 373 GetBoundsInRootWindow().Intersect(work_area); |
374 if (transient_parent_rect.height() >= size.height() && | 374 if (transient_parent_rect.height() >= size.height() && |
375 transient_parent_rect.width() >= size.width()) | 375 transient_parent_rect.width() >= size.width()) |
376 parent_bounds = transient_parent_rect; | 376 parent_bounds = transient_parent_rect; |
377 } | 377 } |
378 | 378 |
379 gfx::Rect window_bounds( | 379 gfx::Rect window_bounds( |
380 parent_bounds.x() + (parent_bounds.width() - size.width()) / 2, | 380 parent_bounds.x() + (parent_bounds.width() - size.width()) / 2, |
381 parent_bounds.y() + (parent_bounds.height() - size.height()) / 2, | 381 parent_bounds.y() + (parent_bounds.height() - size.height()) / 2, |
382 size.width(), | 382 size.width(), |
383 size.height()); | 383 size.height()); |
384 window_bounds = window_bounds.AdjustToFit(work_area); | 384 // Don't size the window bigger than the parent, otherwise the user may not be |
| 385 // able to close or move it. |
| 386 window_bounds = window_bounds.AdjustToFit(parent_bounds); |
385 | 387 |
386 // Convert the bounds back relative to the parent. | 388 // Convert the bounds back relative to the parent. |
387 gfx::Point origin = window_bounds.origin(); | 389 gfx::Point origin = window_bounds.origin(); |
388 aura::Window::ConvertPointToWindow(window_->GetRootWindow(), | 390 aura::Window::ConvertPointToWindow(window_->GetRootWindow(), |
389 window_->parent(), &origin); | 391 window_->parent(), &origin); |
390 window_bounds.set_origin(origin); | 392 window_bounds.set_origin(origin); |
391 window_->SetBounds(window_bounds); | 393 window_->SetBounds(window_bounds); |
392 } | 394 } |
393 | 395 |
394 void NativeWidgetAura::GetWindowPlacement( | 396 void NativeWidgetAura::GetWindowPlacement( |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1046 return aura::Env::GetInstance()->is_mouse_button_down(); | 1048 return aura::Env::GetInstance()->is_mouse_button_down(); |
1047 } | 1049 } |
1048 | 1050 |
1049 // static | 1051 // static |
1050 bool NativeWidgetPrivate::IsTouchDown() { | 1052 bool NativeWidgetPrivate::IsTouchDown() { |
1051 return aura::Env::GetInstance()->is_touch_down(); | 1053 return aura::Env::GetInstance()->is_touch_down(); |
1052 } | 1054 } |
1053 | 1055 |
1054 } // namespace internal | 1056 } // namespace internal |
1055 } // namespace views | 1057 } // namespace views |
OLD | NEW |