Chromium Code Reviews| 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 "ash/display/display_controller.h" | 5 #include "ash/display/display_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
| 10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
| 11 #include "ash/root_window_controller.h" | 11 #include "ash/root_window_controller.h" |
| 12 #include "ash/screen_ash.h" | 12 #include "ash/screen_ash.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/wm/coordinate_conversion.h" | 14 #include "ash/wm/coordinate_conversion.h" |
| 15 #include "ash/wm/property_util.h" | 15 #include "ash/wm/property_util.h" |
| 16 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/json/json_value_converter.h" | 18 #include "base/json/json_value_converter.h" |
| 19 #include "base/string_number_conversions.h" | |
| 19 #include "base/string_piece.h" | 20 #include "base/string_piece.h" |
| 20 #include "base/stringprintf.h" | 21 #include "base/stringprintf.h" |
| 21 #include "base/values.h" | 22 #include "base/values.h" |
| 22 #include "ui/aura/client/screen_position_client.h" | 23 #include "ui/aura/client/screen_position_client.h" |
| 23 #include "ui/aura/env.h" | 24 #include "ui/aura/env.h" |
| 24 #include "ui/aura/root_window.h" | 25 #include "ui/aura/root_window.h" |
| 25 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
| 26 #include "ui/compositor/dip_util.h" | 27 #include "ui/compositor/dip_util.h" |
| 27 #include "ui/gfx/display.h" | 28 #include "ui/gfx/display.h" |
| 28 #include "ui/gfx/screen.h" | 29 #include "ui/gfx/screen.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 case DisplayLayout::LEFT: | 97 case DisplayLayout::LEFT: |
| 97 return std::string("left"); | 98 return std::string("left"); |
| 98 } | 99 } |
| 99 return std::string("unknown"); | 100 return std::string("unknown"); |
| 100 } | 101 } |
| 101 | 102 |
| 102 internal::DisplayManager* GetDisplayManager() { | 103 internal::DisplayManager* GetDisplayManager() { |
| 103 return Shell::GetInstance()->display_manager(); | 104 return Shell::GetInstance()->display_manager(); |
| 104 } | 105 } |
| 105 | 106 |
| 107 void SetDisplayPropertiesOnHostWindow(aura::RootWindow* root, | |
| 108 const gfx::Display& display) { | |
| 109 // Native window property (Atom in X11) that specifies the display's | |
| 110 // rotation and scale factor. The value of the rotation is one of 0 | |
| 111 // (normal), 1 (90 degrees clockwise), 2 (180 degree) or 3 (270 | |
|
Daniel Erat
2013/01/30 23:52:46
nit: s/180 degree/180 degrees/
oshima
2013/01/31 00:04:56
Done.
| |
| 112 // degrees clockwise). The value of the scale factor is in | |
| 113 // percent (100, 140, 200 etc). | |
| 114 const char kRotationProp[] = "_CHROME_DISPLAY_ROTATION"; | |
| 115 const char kScaleFactorProp[] = "_CHROME_DISPLAY_SCALE_FACTOR"; | |
| 116 | |
| 117 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 118 int rotation = 0; | |
| 119 if (command_line->HasSwitch(switches::kAshOverrideDisplayOrientation)) { | |
| 120 std::string value = command_line-> | |
| 121 GetSwitchValueASCII(switches::kAshOverrideDisplayOrientation); | |
| 122 DCHECK(base::StringToInt(value, &rotation)); | |
| 123 DCHECK(0 <= rotation && rotation <= 3) << "Invalid rotation value=" | |
| 124 << rotation; | |
| 125 if (rotation < 0 || rotation > 3) | |
| 126 rotation = 0; | |
| 127 } | |
| 128 root->SetHostWindowIntProperty(kRotationProp, rotation); | |
|
Ben Goodger (Google)
2013/01/31 16:57:13
Where is this property read, since you don't provi
oshima
2013/01/31 17:12:53
This will be read by touchpad/mouse driver to
cont
| |
| 129 root->SetHostWindowIntProperty(kScaleFactorProp, | |
| 130 100 * display.device_scale_factor()); | |
| 131 } | |
| 132 | |
| 106 } // namespace | 133 } // namespace |
| 107 | 134 |
| 108 //////////////////////////////////////////////////////////////////////////////// | 135 //////////////////////////////////////////////////////////////////////////////// |
| 109 // DisplayLayout | 136 // DisplayLayout |
| 110 | 137 |
| 111 DisplayLayout::DisplayLayout() | 138 DisplayLayout::DisplayLayout() |
| 112 : position(RIGHT), | 139 : position(RIGHT), |
| 113 offset(0) {} | 140 offset(0) {} |
| 114 | 141 |
| 115 DisplayLayout::DisplayLayout(DisplayLayout::Position position, int offset) | 142 DisplayLayout::DisplayLayout(DisplayLayout::Position position, int offset) |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 primary_candidate = display; | 296 primary_candidate = display; |
| 270 break; | 297 break; |
| 271 } else if (display->bounds_in_pixel().y() < y) { | 298 } else if (display->bounds_in_pixel().y() < y) { |
| 272 primary_candidate = display; | 299 primary_candidate = display; |
| 273 y = display->bounds_in_pixel().y(); | 300 y = display->bounds_in_pixel().y(); |
| 274 } | 301 } |
| 275 } | 302 } |
| 276 } | 303 } |
| 277 #endif | 304 #endif |
| 278 primary_display_id = primary_candidate->id(); | 305 primary_display_id = primary_candidate->id(); |
| 279 aura::RootWindow* root = AddRootWindowForDisplay(*primary_candidate); | 306 AddRootWindowForDisplay(*primary_candidate); |
| 280 root->SetHostBounds(primary_candidate->bounds_in_pixel()); | |
| 281 UpdateDisplayBoundsForLayout(); | 307 UpdateDisplayBoundsForLayout(); |
| 282 } | 308 } |
| 283 | 309 |
| 284 void DisplayController::InitSecondaryDisplays() { | 310 void DisplayController::InitSecondaryDisplays() { |
| 285 internal::DisplayManager* display_manager = GetDisplayManager(); | 311 internal::DisplayManager* display_manager = GetDisplayManager(); |
| 286 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 312 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
| 287 const gfx::Display* display = display_manager->GetDisplayAt(i); | 313 const gfx::Display* display = display_manager->GetDisplayAt(i); |
| 288 if (primary_display_id != display->id()) { | 314 if (primary_display_id != display->id()) { |
| 289 aura::RootWindow* root = AddRootWindowForDisplay(*display); | 315 aura::RootWindow* root = AddRootWindowForDisplay(*display); |
| 290 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); | 316 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 return display_manager->GetDisplayAt(0)->id() == primary_display_id ? | 559 return display_manager->GetDisplayAt(0)->id() == primary_display_id ? |
| 534 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0); | 560 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0); |
| 535 } | 561 } |
| 536 | 562 |
| 537 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { | 563 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { |
| 538 if (limiter_.get()) | 564 if (limiter_.get()) |
| 539 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); | 565 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); |
| 540 | 566 |
| 541 NotifyDisplayConfigurationChanging(); | 567 NotifyDisplayConfigurationChanging(); |
| 542 UpdateDisplayBoundsForLayout(); | 568 UpdateDisplayBoundsForLayout(); |
| 543 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel()); | 569 aura::RootWindow* root = root_windows_[display.id()]; |
| 570 SetDisplayPropertiesOnHostWindow(root, display); | |
| 571 root->SetHostBounds(display.bounds_in_pixel()); | |
| 544 } | 572 } |
| 545 | 573 |
| 546 void DisplayController::OnDisplayAdded(const gfx::Display& display) { | 574 void DisplayController::OnDisplayAdded(const gfx::Display& display) { |
| 547 if (limiter_.get()) | 575 if (limiter_.get()) |
| 548 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); | 576 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); |
| 549 | 577 |
| 550 NotifyDisplayConfigurationChanging(); | 578 NotifyDisplayConfigurationChanging(); |
| 551 if (primary_root_window_for_replace_) { | 579 if (primary_root_window_for_replace_) { |
| 552 DCHECK(root_windows_.empty()); | 580 DCHECK(root_windows_.empty()); |
| 553 primary_display_id = display.id(); | 581 primary_display_id = display.id(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 // root window itself yet because the stack may be using it. | 640 // root window itself yet because the stack may be using it. |
| 613 controller->Shutdown(); | 641 controller->Shutdown(); |
| 614 MessageLoop::current()->DeleteSoon(FROM_HERE, controller); | 642 MessageLoop::current()->DeleteSoon(FROM_HERE, controller); |
| 615 } | 643 } |
| 616 | 644 |
| 617 aura::RootWindow* DisplayController::AddRootWindowForDisplay( | 645 aura::RootWindow* DisplayController::AddRootWindowForDisplay( |
| 618 const gfx::Display& display) { | 646 const gfx::Display& display) { |
| 619 aura::RootWindow* root = | 647 aura::RootWindow* root = |
| 620 GetDisplayManager()->CreateRootWindowForDisplay(display); | 648 GetDisplayManager()->CreateRootWindowForDisplay(display); |
| 621 root_windows_[display.id()] = root; | 649 root_windows_[display.id()] = root; |
| 650 SetDisplayPropertiesOnHostWindow(root, display); | |
| 622 | 651 |
| 623 #if defined(OS_CHROMEOS) | 652 #if defined(OS_CHROMEOS) |
| 624 static bool force_constrain_pointer_to_root = | 653 static bool force_constrain_pointer_to_root = |
| 625 CommandLine::ForCurrentProcess()->HasSwitch( | 654 CommandLine::ForCurrentProcess()->HasSwitch( |
| 626 switches::kAshConstrainPointerToRoot); | 655 switches::kAshConstrainPointerToRoot); |
| 627 if (base::chromeos::IsRunningOnChromeOS() || force_constrain_pointer_to_root) | 656 if (base::chromeos::IsRunningOnChromeOS() || force_constrain_pointer_to_root) |
| 628 root->ConfineCursorToWindow(); | 657 root->ConfineCursorToWindow(); |
| 629 #endif | 658 #endif |
| 630 return root; | 659 return root; |
| 631 } | 660 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 secondary_display->set_bounds( | 705 secondary_display->set_bounds( |
| 677 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 706 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
| 678 secondary_display->UpdateWorkAreaFromInsets(insets); | 707 secondary_display->UpdateWorkAreaFromInsets(insets); |
| 679 } | 708 } |
| 680 | 709 |
| 681 void DisplayController::NotifyDisplayConfigurationChanging() { | 710 void DisplayController::NotifyDisplayConfigurationChanging() { |
| 682 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); | 711 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); |
| 683 } | 712 } |
| 684 | 713 |
| 685 } // namespace ash | 714 } // namespace ash |
| OLD | NEW |