Chromium Code Reviews| Index: ash/display/display_controller.cc |
| diff --git a/ash/display/display_controller.cc b/ash/display/display_controller.cc |
| index 7954d44ac9e84e8d0762880499c8ca11290bd3fb..69c0ab28cc461dea92298caf2ce9e4ca8609ade8 100644 |
| --- a/ash/display/display_controller.cc |
| +++ b/ash/display/display_controller.cc |
| @@ -15,6 +15,9 @@ |
| #include "ash/wm/property_util.h" |
| #include "ash/wm/window_util.h" |
| #include "base/command_line.h" |
| +#include "base/json/json_value_converter.h" |
| +#include "base/string_piece.h" |
| +#include "base/values.h" |
| #include "ui/aura/client/screen_position_client.h" |
| #include "ui/aura/env.h" |
| #include "ui/aura/root_window.h" |
| @@ -31,12 +34,66 @@ namespace { |
| // in case that the offset value is too large. |
| const int kMinimumOverlapForInvalidOffset = 50; |
| +bool GetPositionFromString(const base::StringPiece& position, |
| + DisplayLayout::Position* field) { |
| + if (position == "top") { |
| + *field = DisplayLayout::TOP; |
| + return true; |
| + } else if (position == "bottom") { |
| + *field = DisplayLayout::BOTTOM; |
| + return true; |
| + } else if (position == "right") { |
| + *field = DisplayLayout::RIGHT; |
| + return true; |
| + } else if (position == "left") { |
| + *field = DisplayLayout::LEFT; |
| + return true; |
| + } |
|
oshima
2012/08/27 23:00:46
log if the position is not one of value above.
Jun Mukai
2012/08/28 08:12:42
Done.
|
| + |
| + return false; |
| +} |
| + |
| +} // namespace |
| + |
| +DisplayLayout::DisplayLayout() |
| + : position(RIGHT), offset(0) {} |
| + |
| +DisplayLayout::DisplayLayout(DisplayLayout::Position p, int o) |
| + : position(p), offset(o) {} |
|
oshima
2012/08/27 23:00:46
you probably want to check the range of both posit
Jun Mukai
2012/08/28 08:12:42
Added DCHECK for position. The offset value valid
|
| + |
| +void DisplayLayout::RegisterJSONConverter( |
| + base::JSONValueConverter<DisplayLayout>* converter) { |
| + converter->RegisterCustomField<Position>( |
| + "position", &DisplayLayout::position, &GetPositionFromString); |
| + converter->RegisterIntField("offset", &DisplayLayout::offset); |
| +} |
| + |
| +bool DisplayLayout::GetValue(base::DictionaryValue* value) { |
| + std::string position_value; |
| + switch (position) { |
| + case TOP: |
| + position_value = "top"; |
| + break; |
| + case BOTTOM: |
| + position_value = "bottom"; |
| + break; |
| + case RIGHT: |
| + position_value = "right"; |
| + break; |
| + case LEFT: |
| + position_value = "left"; |
| + break; |
|
oshima
2012/08/27 23:00:46
default:
return false;
is better.
Jun Mukai
2012/08/28 08:12:42
Done.
|
| + } |
| + if (position_value.empty()) |
|
oshima
2012/08/27 23:00:46
if you're worrying about fall through, it should b
Jun Mukai
2012/08/28 08:12:42
removed.
|
| + return false; |
| + |
| + value->SetString("position", position_value); |
| + value->SetInteger("offset", offset); |
| + return true; |
| } |
| DisplayController::DisplayController() |
| - : secondary_display_layout_(RIGHT), |
| - secondary_display_offset_(0), |
| - dont_warp_mouse_(false) { |
| + : dont_warp_mouse_(false) { |
| aura::Env::GetInstance()->display_manager()->AddObserver(this); |
| } |
| @@ -129,16 +186,32 @@ DisplayController::GetAllRootWindowControllers() { |
| } |
| void DisplayController::SetSecondaryDisplayLayout( |
| - SecondaryDisplayLayout layout) { |
| - secondary_display_layout_ = layout; |
| + DisplayLayout::Position position) { |
| + default_display_layout_.position = position; |
| UpdateDisplayBoundsForLayout(); |
| } |
| void DisplayController::SetSecondaryDisplayOffset(int offset) { |
| - secondary_display_offset_ = offset; |
| + default_display_layout_.offset = offset; |
| UpdateDisplayBoundsForLayout(); |
| } |
| +void DisplayController::SetDisplayLayoutForName(const std::string& name, |
| + const base::Value& value) { |
| + base::JSONValueConverter<DisplayLayout> converter; |
| + DisplayLayout layout; |
| + if (!converter.Convert(value, &layout)) |
| + return; |
| + |
| + secondary_layouts_[name] = layout; |
| + UpdateDisplayBoundsForLayout(); |
| +} |
| + |
| +void DisplayController::GetLayoutForDisplay(const gfx::Display& display, |
| + int* layout, int* offset) { |
| + // TODO |
| +} |
| + |
| bool DisplayController::WarpMouseCursorIfNecessary( |
| aura::RootWindow* current_root, |
| const gfx::Point& point_in_root) { |
| @@ -255,15 +328,24 @@ void DisplayController::UpdateDisplayBoundsForLayout() { |
| aura::Env::GetInstance()->display_manager(); |
| const gfx::Rect& primary_bounds = display_manager->GetDisplayAt(0)->bounds(); |
| gfx::Display* secondary_display = display_manager->GetDisplayAt(1); |
| + const std::string& secondary_name = display_manager->GetDisplayNameAt(1); |
| const gfx::Rect& secondary_bounds = secondary_display->bounds(); |
| gfx::Point new_secondary_origin = primary_bounds.origin(); |
| // TODO(oshima|mukai): Implement more flexible layout. |
| + const DisplayLayout* layout = &default_display_layout_; |
| + std::map<std::string, DisplayLayout>::const_iterator iter = |
| + secondary_layouts_.find(secondary_name); |
| + if (iter != secondary_layouts_.end()) |
| + layout = &iter->second; |
| + |
| + DisplayLayout::Position position = layout->position; |
| + |
| // Ignore the offset in case the secondary display doesn't share edges with |
| // the primary display. |
| - int offset = secondary_display_offset_; |
| - if (secondary_display_layout_ == TOP || secondary_display_layout_ == BOTTOM) { |
| + int offset = layout->offset; |
| + if (position == DisplayLayout::TOP || position == DisplayLayout::BOTTOM) { |
| offset = std::min( |
| offset, primary_bounds.width() - kMinimumOverlapForInvalidOffset); |
| offset = std::max( |
| @@ -274,17 +356,17 @@ void DisplayController::UpdateDisplayBoundsForLayout() { |
| offset = std::max( |
| offset, -secondary_bounds.height() + kMinimumOverlapForInvalidOffset); |
| } |
| - switch (secondary_display_layout_) { |
| - case TOP: |
| + switch (position) { |
| + case DisplayLayout::TOP: |
| new_secondary_origin.Offset(offset, -secondary_bounds.height()); |
| break; |
| - case RIGHT: |
| + case DisplayLayout::RIGHT: |
| new_secondary_origin.Offset(primary_bounds.width(), offset); |
| break; |
| - case BOTTOM: |
| + case DisplayLayout::BOTTOM: |
| new_secondary_origin.Offset(offset, primary_bounds.height()); |
| break; |
| - case LEFT: |
| + case DisplayLayout::LEFT: |
| new_secondary_origin.Offset(-secondary_bounds.width(), offset); |
| break; |
| } |