devtools_contents_resizing_strategy.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "brightray/browser/devtools_contents_resizing_strategy.h"
  5. #include <algorithm>
  6. DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy()
  7. : hide_inspected_contents_(false) {}
  8. DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy(
  9. const gfx::Rect& bounds)
  10. : bounds_(bounds),
  11. hide_inspected_contents_(bounds_.IsEmpty() && !bounds_.x() &&
  12. !bounds_.y()) {}
  13. void DevToolsContentsResizingStrategy::CopyFrom(
  14. const DevToolsContentsResizingStrategy& strategy) {
  15. bounds_ = strategy.bounds();
  16. hide_inspected_contents_ = strategy.hide_inspected_contents();
  17. }
  18. bool DevToolsContentsResizingStrategy::Equals(
  19. const DevToolsContentsResizingStrategy& strategy) {
  20. return bounds_ == strategy.bounds() &&
  21. hide_inspected_contents_ == strategy.hide_inspected_contents();
  22. }
  23. void ApplyDevToolsContentsResizingStrategy(
  24. const DevToolsContentsResizingStrategy& strategy,
  25. const gfx::Size& container_size,
  26. gfx::Rect* new_devtools_bounds,
  27. gfx::Rect* new_contents_bounds) {
  28. new_devtools_bounds->SetRect(0, 0, container_size.width(),
  29. container_size.height());
  30. const gfx::Rect& bounds = strategy.bounds();
  31. if (bounds.size().IsEmpty() && !strategy.hide_inspected_contents()) {
  32. new_contents_bounds->SetRect(0, 0, container_size.width(),
  33. container_size.height());
  34. return;
  35. }
  36. int left = std::min(bounds.x(), container_size.width());
  37. int top = std::min(bounds.y(), container_size.height());
  38. int width = std::min(bounds.width(), container_size.width() - left);
  39. int height = std::min(bounds.height(), container_size.height() - top);
  40. new_contents_bounds->SetRect(left, top, width, height);
  41. }