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" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
| 24 #include "ui/aura/root_window.h" | 24 #include "ui/aura/root_window.h" |
| 25 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
| 26 #include "ui/compositor/dip_util.h" | 26 #include "ui/compositor/dip_util.h" |
| 27 #include "ui/gfx/display.h" | 27 #include "ui/gfx/display.h" |
| 28 #include "ui/gfx/screen.h" | 28 #include "ui/gfx/screen.h" |
| 29 | 29 |
| 30 #if defined(OS_CHROMEOS) | 30 #if defined(OS_CHROMEOS) |
| 31 #include "ash/display/output_configurator_animation.h" | 31 #include "ash/display/output_configurator_animation.h" |
| 32 #include "base/chromeos/chromeos_version.h" | 32 #include "base/chromeos/chromeos_version.h" |
| 33 #include "base/string_number_conversions.h" | |
| 33 #include "base/time.h" | 34 #include "base/time.h" |
| 34 #include "chromeos/display/output_configurator.h" | 35 #include "chromeos/display/output_configurator.h" |
| 36 #include "ui/base/x/x11_util.h" | |
| 35 #endif // defined(OS_CHROMEOS) | 37 #endif // defined(OS_CHROMEOS) |
| 36 | 38 |
| 37 | 39 |
| 38 namespace ash { | 40 namespace ash { |
| 39 namespace { | 41 namespace { |
| 40 | 42 |
| 41 // Primary display stored in global object as it can be | 43 // Primary display stored in global object as it can be |
| 42 // accessed after Shell is deleted. A separate display instance is created | 44 // accessed after Shell is deleted. A separate display instance is created |
| 43 // during the shutdown instead of always keeping two display instances | 45 // during the shutdown instead of always keeping two display instances |
| 44 // (one here and another one in display_manager) in sync, which is error prone. | 46 // (one here and another one in display_manager) in sync, which is error prone. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 case DisplayLayout::LEFT: | 98 case DisplayLayout::LEFT: |
| 97 return std::string("left"); | 99 return std::string("left"); |
| 98 } | 100 } |
| 99 return std::string("unknown"); | 101 return std::string("unknown"); |
| 100 } | 102 } |
| 101 | 103 |
| 102 internal::DisplayManager* GetDisplayManager() { | 104 internal::DisplayManager* GetDisplayManager() { |
| 103 return Shell::GetInstance()->display_manager(); | 105 return Shell::GetInstance()->display_manager(); |
| 104 } | 106 } |
| 105 | 107 |
| 108 void SetDisplayPropertiesOnHostWindow(aura::RootWindow* root, | |
| 109 const gfx::Display& display) { | |
| 110 #if defined(OS_CHROMEOS) | |
| 111 // Native window property (Atom in X11) that specifies the display's | |
| 112 // rotation and scale factor. They are read and used by | |
| 113 // touchpad/mouse driver directly on X (contact adlr@ for more | |
| 114 // details on touchpad/mouse driver side). The value of the rotation | |
| 115 // is one of 0 (normal), 1 (90 degrees clockwise), 2 (180 degree) or | |
| 116 // 3 (270 degrees clockwise). The value of the scale factor is in | |
| 117 // percent (100, 140, 200 etc). | |
| 118 const char kRotationProp[] = "_CHROME_DISPLAY_ROTATION"; | |
| 119 const char kScaleFactorProp[] = "_CHROME_DISPLAY_SCALE_FACTOR"; | |
| 120 const char CARDINAL[] = "CARDINAL"; | |
|
Daniel Erat
2013/01/31 22:38:29
kCardinal
oshima
2013/01/31 22:48:32
Done.
| |
| 121 | |
| 122 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 123 int rotation = 0; | |
| 124 if (command_line->HasSwitch(switches::kAshOverrideDisplayOrientation)) { | |
| 125 std::string value = command_line-> | |
| 126 GetSwitchValueASCII(switches::kAshOverrideDisplayOrientation); | |
| 127 DCHECK(base::StringToInt(value, &rotation)); | |
| 128 DCHECK(0 <= rotation && rotation <= 3) << "Invalid rotation value=" | |
| 129 << rotation; | |
| 130 if (rotation < 0 || rotation > 3) | |
| 131 rotation = 0; | |
| 132 } | |
| 133 gfx::AcceleratedWidget xwindow = root->GetAcceleratedWidget(); | |
| 134 ui::SetIntProperty(xwindow, kRotationProp, CARDINAL, rotation); | |
| 135 ui::SetIntProperty( | |
| 136 xwindow, kScaleFactorProp, CARDINAL, 100 * display.device_scale_factor()); | |
| 137 #endif | |
| 138 } | |
| 139 | |
| 106 } // namespace | 140 } // namespace |
| 107 | 141 |
| 108 //////////////////////////////////////////////////////////////////////////////// | 142 //////////////////////////////////////////////////////////////////////////////// |
| 109 // DisplayLayout | 143 // DisplayLayout |
| 110 | 144 |
| 111 DisplayLayout::DisplayLayout() | 145 DisplayLayout::DisplayLayout() |
| 112 : position(RIGHT), | 146 : position(RIGHT), |
| 113 offset(0) {} | 147 offset(0) {} |
| 114 | 148 |
| 115 DisplayLayout::DisplayLayout(DisplayLayout::Position position, int offset) | 149 DisplayLayout::DisplayLayout(DisplayLayout::Position position, int offset) |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 primary_candidate = display; | 303 primary_candidate = display; |
| 270 break; | 304 break; |
| 271 } else if (display->bounds_in_pixel().y() < y) { | 305 } else if (display->bounds_in_pixel().y() < y) { |
| 272 primary_candidate = display; | 306 primary_candidate = display; |
| 273 y = display->bounds_in_pixel().y(); | 307 y = display->bounds_in_pixel().y(); |
| 274 } | 308 } |
| 275 } | 309 } |
| 276 } | 310 } |
| 277 #endif | 311 #endif |
| 278 primary_display_id = primary_candidate->id(); | 312 primary_display_id = primary_candidate->id(); |
| 279 aura::RootWindow* root = AddRootWindowForDisplay(*primary_candidate); | 313 AddRootWindowForDisplay(*primary_candidate); |
| 280 root->SetHostBounds(primary_candidate->bounds_in_pixel()); | |
| 281 UpdateDisplayBoundsForLayout(); | 314 UpdateDisplayBoundsForLayout(); |
| 282 } | 315 } |
| 283 | 316 |
| 284 void DisplayController::InitSecondaryDisplays() { | 317 void DisplayController::InitSecondaryDisplays() { |
| 285 internal::DisplayManager* display_manager = GetDisplayManager(); | 318 internal::DisplayManager* display_manager = GetDisplayManager(); |
| 286 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 319 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
| 287 const gfx::Display* display = display_manager->GetDisplayAt(i); | 320 const gfx::Display* display = display_manager->GetDisplayAt(i); |
| 288 if (primary_display_id != display->id()) { | 321 if (primary_display_id != display->id()) { |
| 289 aura::RootWindow* root = AddRootWindowForDisplay(*display); | 322 aura::RootWindow* root = AddRootWindowForDisplay(*display); |
| 290 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); | 323 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 ? | 566 return display_manager->GetDisplayAt(0)->id() == primary_display_id ? |
| 534 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0); | 567 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0); |
| 535 } | 568 } |
| 536 | 569 |
| 537 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { | 570 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { |
| 538 if (limiter_.get()) | 571 if (limiter_.get()) |
| 539 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); | 572 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); |
| 540 | 573 |
| 541 NotifyDisplayConfigurationChanging(); | 574 NotifyDisplayConfigurationChanging(); |
| 542 UpdateDisplayBoundsForLayout(); | 575 UpdateDisplayBoundsForLayout(); |
| 543 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel()); | 576 aura::RootWindow* root = root_windows_[display.id()]; |
| 577 SetDisplayPropertiesOnHostWindow(root, display); | |
| 578 root->SetHostBounds(display.bounds_in_pixel()); | |
| 544 } | 579 } |
| 545 | 580 |
| 546 void DisplayController::OnDisplayAdded(const gfx::Display& display) { | 581 void DisplayController::OnDisplayAdded(const gfx::Display& display) { |
| 547 if (limiter_.get()) | 582 if (limiter_.get()) |
| 548 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); | 583 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); |
| 549 | 584 |
| 550 NotifyDisplayConfigurationChanging(); | 585 NotifyDisplayConfigurationChanging(); |
| 551 if (primary_root_window_for_replace_) { | 586 if (primary_root_window_for_replace_) { |
| 552 DCHECK(root_windows_.empty()); | 587 DCHECK(root_windows_.empty()); |
| 553 primary_display_id = display.id(); | 588 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. | 647 // root window itself yet because the stack may be using it. |
| 613 controller->Shutdown(); | 648 controller->Shutdown(); |
| 614 MessageLoop::current()->DeleteSoon(FROM_HERE, controller); | 649 MessageLoop::current()->DeleteSoon(FROM_HERE, controller); |
| 615 } | 650 } |
| 616 | 651 |
| 617 aura::RootWindow* DisplayController::AddRootWindowForDisplay( | 652 aura::RootWindow* DisplayController::AddRootWindowForDisplay( |
| 618 const gfx::Display& display) { | 653 const gfx::Display& display) { |
| 619 aura::RootWindow* root = | 654 aura::RootWindow* root = |
| 620 GetDisplayManager()->CreateRootWindowForDisplay(display); | 655 GetDisplayManager()->CreateRootWindowForDisplay(display); |
| 621 root_windows_[display.id()] = root; | 656 root_windows_[display.id()] = root; |
| 657 SetDisplayPropertiesOnHostWindow(root, display); | |
| 622 | 658 |
| 623 #if defined(OS_CHROMEOS) | 659 #if defined(OS_CHROMEOS) |
| 624 static bool force_constrain_pointer_to_root = | 660 static bool force_constrain_pointer_to_root = |
| 625 CommandLine::ForCurrentProcess()->HasSwitch( | 661 CommandLine::ForCurrentProcess()->HasSwitch( |
| 626 switches::kAshConstrainPointerToRoot); | 662 switches::kAshConstrainPointerToRoot); |
| 627 if (base::chromeos::IsRunningOnChromeOS() || force_constrain_pointer_to_root) | 663 if (base::chromeos::IsRunningOnChromeOS() || force_constrain_pointer_to_root) |
| 628 root->ConfineCursorToWindow(); | 664 root->ConfineCursorToWindow(); |
| 629 #endif | 665 #endif |
| 630 return root; | 666 return root; |
| 631 } | 667 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 secondary_display->set_bounds( | 712 secondary_display->set_bounds( |
| 677 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 713 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
| 678 secondary_display->UpdateWorkAreaFromInsets(insets); | 714 secondary_display->UpdateWorkAreaFromInsets(insets); |
| 679 } | 715 } |
| 680 | 716 |
| 681 void DisplayController::NotifyDisplayConfigurationChanging() { | 717 void DisplayController::NotifyDisplayConfigurationChanging() { |
| 682 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); | 718 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); |
| 683 } | 719 } |
| 684 | 720 |
| 685 } // namespace ash | 721 } // namespace ash |
| OLD | NEW |