| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "athena/wm/overview_toolbar.h" | 5 #include "athena/wm/overview_toolbar.h" |
| 6 | 6 |
| 7 #include "athena/resources/grit/athena_resources.h" | 7 #include "athena/resources/grit/athena_resources.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 int resource_id_; | 92 int resource_id_; |
| 93 base::string16 label_; | 93 base::string16 label_; |
| 94 scoped_ptr<ui::Layer> layer_; | 94 scoped_ptr<ui::Layer> layer_; |
| 95 | 95 |
| 96 DISALLOW_COPY_AND_ASSIGN(ActionButton); | 96 DISALLOW_COPY_AND_ASSIGN(ActionButton); |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 OverviewToolbar::OverviewToolbar(aura::Window* container) | 99 OverviewToolbar::OverviewToolbar(aura::Window* container) |
| 100 : shown_(false), | 100 : shown_(false), |
| 101 disabled_action_bitfields_(0), |
| 101 close_(new ActionButton(IDR_ATHENA_OVERVIEW_TRASH, "Close")), | 102 close_(new ActionButton(IDR_ATHENA_OVERVIEW_TRASH, "Close")), |
| 102 split_(new ActionButton(IDR_ATHENA_OVERVIEW_SPLIT, "Split")), | 103 split_(new ActionButton(IDR_ATHENA_OVERVIEW_SPLIT, "Split")), |
| 103 current_action_(ACTION_TYPE_NONE), | 104 current_action_(ACTION_TYPE_NONE), |
| 104 container_bounds_(container->bounds()) { | 105 container_bounds_(container->bounds()) { |
| 105 const int kPaddingFromBottom = 200; | 106 const int kPaddingFromBottom = 200; |
| 106 const int kPaddingBetweenButtons = 200; | 107 const int kPaddingBetweenButtons = 200; |
| 107 | 108 |
| 108 int x = container_bounds_.right() - | 109 int x = container_bounds_.right() - |
| 109 (kActionButtonPaddingFromRight + kActionButtonImageSize); | 110 (kActionButtonPaddingFromRight + kActionButtonImageSize); |
| 110 int y = container_bounds_.bottom() - | 111 int y = container_bounds_.bottom() - |
| (...skipping 10 matching lines...) Expand all Loading... |
| 121 // If the buttons are visible, then fade them out, instead of destroying them | 122 // If the buttons are visible, then fade them out, instead of destroying them |
| 122 // immediately. | 123 // immediately. |
| 123 if (shown_) { | 124 if (shown_) { |
| 124 ActionButton::DestroyAfterFadeout(split_.Pass()); | 125 ActionButton::DestroyAfterFadeout(split_.Pass()); |
| 125 ActionButton::DestroyAfterFadeout(close_.Pass()); | 126 ActionButton::DestroyAfterFadeout(close_.Pass()); |
| 126 } | 127 } |
| 127 } | 128 } |
| 128 | 129 |
| 129 OverviewToolbar::ActionType OverviewToolbar::GetHighlightAction( | 130 OverviewToolbar::ActionType OverviewToolbar::GetHighlightAction( |
| 130 const ui::GestureEvent& event) const { | 131 const ui::GestureEvent& event) const { |
| 131 if (IsEventOverButton(split_.get(), event)) | 132 if (IsActionEnabled(ACTION_TYPE_SPLIT) && |
| 133 IsEventOverButton(split_.get(), event)) |
| 132 return ACTION_TYPE_SPLIT; | 134 return ACTION_TYPE_SPLIT; |
| 133 if (IsEventOverButton(close_.get(), event)) | 135 if (IsActionEnabled(ACTION_TYPE_CLOSE) && |
| 136 IsEventOverButton(close_.get(), event)) |
| 134 return ACTION_TYPE_CLOSE; | 137 return ACTION_TYPE_CLOSE; |
| 135 return ACTION_TYPE_NONE; | 138 return ACTION_TYPE_NONE; |
| 136 } | 139 } |
| 137 | 140 |
| 138 void OverviewToolbar::SetHighlightAction(ActionType action) { | 141 void OverviewToolbar::SetHighlightAction(ActionType action) { |
| 142 CHECK(IsActionEnabled(action)); |
| 139 if (current_action_ == action) | 143 if (current_action_ == action) |
| 140 return; | 144 return; |
| 141 current_action_ = action; | 145 current_action_ = action; |
| 142 if (!shown_) { | 146 if (!shown_) { |
| 143 ShowActionButtons(); | 147 ShowActionButtons(); |
| 144 } else { | 148 } else { |
| 145 TransformButton(close_.get()); | 149 TransformButton(close_.get()); |
| 146 TransformButton(split_.get()); | 150 TransformButton(split_.get()); |
| 147 } | 151 } |
| 148 } | 152 } |
| 149 | 153 |
| 150 void OverviewToolbar::ShowActionButtons() { | 154 void OverviewToolbar::ShowActionButtons() { |
| 151 if (!shown_) | 155 if (!shown_) |
| 152 ToggleActionButtonsVisibility(); | 156 ToggleActionButtonsVisibility(); |
| 153 } | 157 } |
| 154 | 158 |
| 155 void OverviewToolbar::HideActionButtons() { | 159 void OverviewToolbar::HideActionButtons() { |
| 156 if (shown_) | 160 if (shown_) |
| 157 ToggleActionButtonsVisibility(); | 161 ToggleActionButtonsVisibility(); |
| 158 } | 162 } |
| 159 | 163 |
| 164 void OverviewToolbar::DisableAction(ActionType action) { |
| 165 CHECK_NE(current_action_, action); |
| 166 disabled_action_bitfields_ |= (1u << action); |
| 167 } |
| 168 |
| 160 void OverviewToolbar::ToggleActionButtonsVisibility() { | 169 void OverviewToolbar::ToggleActionButtonsVisibility() { |
| 161 shown_ = !shown_; | 170 shown_ = !shown_; |
| 162 TransformButton(close_.get()); | 171 TransformButton(close_.get()); |
| 163 TransformButton(split_.get()); | 172 TransformButton(split_.get()); |
| 164 } | 173 } |
| 165 | 174 |
| 175 bool OverviewToolbar::IsActionEnabled(ActionType action) const { |
| 176 return !(disabled_action_bitfields_ & (1u << action)); |
| 177 } |
| 178 |
| 166 bool OverviewToolbar::IsEventOverButton(ActionButton* button, | 179 bool OverviewToolbar::IsEventOverButton(ActionButton* button, |
| 167 const ui::GestureEvent& event) const { | 180 const ui::GestureEvent& event) const { |
| 168 const int kBoundsInsetForTarget = 30; | 181 const int kBoundsInsetForTarget = 30; |
| 169 gfx::RectF bounds = button->layer()->bounds(); | 182 gfx::RectF bounds = button->layer()->bounds(); |
| 170 bounds.Inset(-kBoundsInsetForTarget, -kBoundsInsetForTarget); | 183 bounds.Inset(-kBoundsInsetForTarget, -kBoundsInsetForTarget); |
| 171 return bounds.Contains(event.location()); | 184 return bounds.Contains(event.location()); |
| 172 } | 185 } |
| 173 | 186 |
| 174 gfx::Transform OverviewToolbar::ComputeTransformFor( | 187 gfx::Transform OverviewToolbar::ComputeTransformFor( |
| 175 ActionButton* button) const { | 188 ActionButton* button) const { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 186 transform.Scale(kHighlightScale, kHighlightScale); | 199 transform.Scale(kHighlightScale, kHighlightScale); |
| 187 } | 200 } |
| 188 return transform; | 201 return transform; |
| 189 } | 202 } |
| 190 | 203 |
| 191 void OverviewToolbar::TransformButton(ActionButton* button) { | 204 void OverviewToolbar::TransformButton(ActionButton* button) { |
| 192 ui::ScopedLayerAnimationSettings split_settings( | 205 ui::ScopedLayerAnimationSettings split_settings( |
| 193 button->layer()->GetAnimator()); | 206 button->layer()->GetAnimator()); |
| 194 split_settings.SetTweenType(gfx::Tween::SMOOTH_IN_OUT); | 207 split_settings.SetTweenType(gfx::Tween::SMOOTH_IN_OUT); |
| 195 button->layer()->SetTransform(ComputeTransformFor(button)); | 208 button->layer()->SetTransform(ComputeTransformFor(button)); |
| 196 button->layer()->SetOpacity(shown_ ? 1 : 0); | 209 bool button_is_enabled = |
| 210 (button == close_.get() && IsActionEnabled(ACTION_TYPE_CLOSE)) || |
| 211 (button == split_.get() && IsActionEnabled(ACTION_TYPE_SPLIT)); |
| 212 button->layer()->SetOpacity((button_is_enabled && shown_) ? 1 : 0); |
| 197 } | 213 } |
| 198 | 214 |
| 199 } // namespace athena | 215 } // namespace athena |
| OLD | NEW |