[go: nahoru, domu]

[CrOS PhoneHub] Updates bubble width.

This CL updates the bubble width to use |kTrayMenuWidth|. This CL also
includes minor refactoring such as:
- Replaces hard-coded constants with calculation.
- Introduces ui_constants.h to store both appearance and URL constants.

Screenshot: https://screenshot.googleplex.com/6PBiuFovTjyfjaa.png

BUG=1143058,1106937

Change-Id: Icdf17321a9acd9be53b7287023e197e027fcac62
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2510551
Commit-Queue: Meilin Wang <meilinw@chromium.org>
Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: Tim Song <tengs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822893}
diff --git a/ash/system/phonehub/task_continuation_view.cc b/ash/system/phonehub/task_continuation_view.cc
index 2ebdd48..c6b2d3f 100644
--- a/ash/system/phonehub/task_continuation_view.cc
+++ b/ash/system/phonehub/task_continuation_view.cc
@@ -8,6 +8,8 @@
 #include "ash/style/ash_color_provider.h"
 #include "ash/system/phonehub/continue_browsing_chip.h"
 #include "ash/system/phonehub/phone_hub_view_ids.h"
+#include "ash/system/phonehub/ui_constants.h"
+#include "ash/system/tray/tray_constants.h"
 #include "ui/base/l10n/l10n_util.h"
 #include "ui/gfx/geometry/insets.h"
 #include "ui/gfx/text_constants.h"
@@ -21,16 +23,25 @@
 namespace {
 
 // Appearance constants in dip.
-constexpr gfx::Size kTaskContinuationChipSize(176, 96);
+constexpr int kTaskContinuationChipHeight = 96;
 constexpr int kTaskContinuationChipsInRow = 2;
 constexpr int kTaskContinuationChipSpacing = 8;
-constexpr int kTaskContinuationChipHorizontalPadding = 4;
+constexpr int kTaskContinuationChipHorizontalSidePadding = 4;
 constexpr int kTaskContinuationChipVerticalPadding = 4;
 constexpr int kHeaderLabelLineHeight = 48;
 
 // Typography.
 constexpr int kHeaderTextFontSizeDip = 15;
 
+gfx::Size GetTaskContinuationChipSize() {
+  int width =
+      (kTrayMenuWidth - kBubbleHorizontalSidePaddingDip * 2 -
+       kTaskContinuationChipHorizontalSidePadding * 2 -
+       kTaskContinuationChipSpacing * (kTaskContinuationChipsInRow - 1)) /
+      kTaskContinuationChipsInRow;
+  return gfx::Size(width, kTaskContinuationChipHeight);
+}
+
 class HeaderView : public views::Label {
  public:
   HeaderView() {
@@ -101,16 +112,16 @@
 
 // views::View:
 gfx::Size TaskContinuationView::TaskChipsView::CalculatePreferredSize() const {
-  int width = kTaskContinuationChipSize.width() * kTaskContinuationChipsInRow +
+  auto chip_size = GetTaskContinuationChipSize();
+  int width = chip_size.width() * kTaskContinuationChipsInRow +
               kTaskContinuationChipSpacing +
-              2 * kTaskContinuationChipHorizontalPadding;
+              2 * kTaskContinuationChipHorizontalSidePadding;
   int rows_num =
       std::ceil((double)task_chips_.view_size() / kTaskContinuationChipsInRow);
-  int height = (kTaskContinuationChipSize.height() +
-                kTaskContinuationChipVerticalPadding) *
+  int height = (chip_size.height() + kTaskContinuationChipVerticalPadding) *
                    std::max(0, rows_num - 1) +
-               kTaskContinuationChipSize.height() +
-               2 * kTaskContinuationChipHorizontalPadding;
+               chip_size.height() +
+               2 * kTaskContinuationChipHorizontalSidePadding;
   return gfx::Size(width, height);
 }
 
@@ -133,14 +144,12 @@
 }
 
 gfx::Point TaskContinuationView::TaskChipsView::GetButtonPosition(int index) {
+  auto chip_size = GetTaskContinuationChipSize();
   int row = index / kTaskContinuationChipsInRow;
   int column = index % kTaskContinuationChipsInRow;
-  int x = (kTaskContinuationChipSize.width() + kTaskContinuationChipSpacing) *
-              column +
-          kTaskContinuationChipHorizontalPadding;
-  int y = (kTaskContinuationChipSize.height() +
-           kTaskContinuationChipVerticalPadding) *
-              row +
+  int x = (chip_size.width() + kTaskContinuationChipSpacing) * column +
+          kTaskContinuationChipHorizontalSidePadding;
+  int y = (chip_size.height() + kTaskContinuationChipVerticalPadding) * row +
           kTaskContinuationChipVerticalPadding;
   return gfx::Point(x, y);
 }
@@ -148,7 +157,7 @@
 void TaskContinuationView::TaskChipsView::CalculateIdealBounds() {
   for (int i = 0; i < task_chips_.view_size(); ++i) {
     gfx::Rect tile_bounds =
-        gfx::Rect(GetButtonPosition(i), kTaskContinuationChipSize);
+        gfx::Rect(GetButtonPosition(i), GetTaskContinuationChipSize());
     task_chips_.set_ideal_bounds(i, tile_bounds);
   }
 }