| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/panels/panel_scroller.h" | 5 #include "chrome/browser/chromeos/panels/panel_scroller.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 widget->Init(NULL, gfx::Rect(0, 0, 100, 800)); | 86 widget->Init(NULL, gfx::Rect(0, 0, 100, 800)); |
| 87 | 87 |
| 88 PanelScroller* scroller = new PanelScroller(); | 88 PanelScroller* scroller = new PanelScroller(); |
| 89 widget->SetContentsView(scroller); | 89 widget->SetContentsView(scroller); |
| 90 | 90 |
| 91 widget->Show(); | 91 widget->Show(); |
| 92 | 92 |
| 93 return scroller; | 93 return scroller; |
| 94 } | 94 } |
| 95 | 95 |
| 96 void PanelScroller::ViewHierarchyChanged(bool is_add, | |
| 97 views::View* parent, | |
| 98 views::View* child) { | |
| 99 // Our child views changed without us knowing it. Stop the animation and mark | |
| 100 // us as dirty (needs_layout_ = true). | |
| 101 animation_.Stop(); | |
| 102 needs_layout_ = true; | |
| 103 } | |
| 104 | |
| 105 gfx::Size PanelScroller::GetPreferredSize() { | 96 gfx::Size PanelScroller::GetPreferredSize() { |
| 106 return gfx::Size(75, 200); | 97 return gfx::Size(75, 200); |
| 107 } | 98 } |
| 108 | 99 |
| 109 void PanelScroller::Layout() { | 100 void PanelScroller::Layout() { |
| 110 /* TODO(brettw) this doesn't work for some reason. | 101 /* TODO(brettw) this doesn't work for some reason. |
| 111 if (!needs_layout_ || !animation_.IsShowing()) | 102 if (!needs_layout_ || !animation_.IsShowing()) |
| 112 return; | 103 return; |
| 113 needs_layout_ = false;*/ | 104 needs_layout_ = false;*/ |
| 114 | 105 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 147 } |
| 157 | 148 |
| 158 bool PanelScroller::OnMousePressed(const views::MouseEvent& event) { | 149 bool PanelScroller::OnMousePressed(const views::MouseEvent& event) { |
| 159 return true; | 150 return true; |
| 160 } | 151 } |
| 161 | 152 |
| 162 bool PanelScroller::OnMouseDragged(const views::MouseEvent& event) { | 153 bool PanelScroller::OnMouseDragged(const views::MouseEvent& event) { |
| 163 return true; | 154 return true; |
| 164 } | 155 } |
| 165 | 156 |
| 166 void PanelScroller::OnMouseReleased(const views::MouseEvent& event, | |
| 167 bool canceled) { | |
| 168 } | |
| 169 | |
| 170 void PanelScroller::HeaderClicked(PanelScrollerHeader* source) { | 157 void PanelScroller::HeaderClicked(PanelScrollerHeader* source) { |
| 171 for (size_t i = 0; i < panels_.size(); i++) { | 158 for (size_t i = 0; i < panels_.size(); i++) { |
| 172 if (panels_[i]->header == source) { | 159 if (panels_[i]->header == source) { |
| 173 ScrollToPanel(static_cast<int>(i)); | 160 ScrollToPanel(static_cast<int>(i)); |
| 174 return; | 161 return; |
| 175 } | 162 } |
| 176 } | 163 } |
| 177 NOTREACHED() << "Invalid panel passed to HeaderClicked."; | 164 NOTREACHED() << "Invalid panel passed to HeaderClicked."; |
| 178 } | 165 } |
| 179 | 166 |
| 167 void PanelScroller::ViewHierarchyChanged(bool is_add, |
| 168 views::View* parent, |
| 169 views::View* child) { |
| 170 // Our child views changed without us knowing it. Stop the animation and mark |
| 171 // us as dirty (needs_layout_ = true). |
| 172 animation_.Stop(); |
| 173 needs_layout_ = true; |
| 174 } |
| 175 |
| 180 void PanelScroller::ScrollToPanel(int index) { | 176 void PanelScroller::ScrollToPanel(int index) { |
| 181 int affected_panel_height = | 177 int affected_panel_height = |
| 182 panels_[index]->container->GetPreferredSize().height(); | 178 panels_[index]->container->GetPreferredSize().height(); |
| 183 | 179 |
| 184 // The pixel size we need to reserve for the stuck headers. | 180 // The pixel size we need to reserve for the stuck headers. |
| 185 int top_stuck_header_pixel_size = index * divider_height_; | 181 int top_stuck_header_pixel_size = index * divider_height_; |
| 186 int bottom_stuck_header_pixel_size = | 182 int bottom_stuck_header_pixel_size = |
| 187 (static_cast<int>(panels_.size()) - index - 1) * divider_height_; | 183 (static_cast<int>(panels_.size()) - index - 1) * divider_height_; |
| 188 | 184 |
| 189 // Compute the offset of the top of the panel to scroll to. | 185 // Compute the offset of the top of the panel to scroll to. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 236 } |
| 241 | 237 |
| 242 void PanelScroller::AnimationProgressed(const ui::Animation* animation) { | 238 void PanelScroller::AnimationProgressed(const ui::Animation* animation) { |
| 243 scroll_pos_ = static_cast<int>( | 239 scroll_pos_ = static_cast<int>( |
| 244 static_cast<double>(animated_scroll_end_ - animated_scroll_begin_) * | 240 static_cast<double>(animated_scroll_end_ - animated_scroll_begin_) * |
| 245 animation_.GetCurrentValue()) + animated_scroll_begin_; | 241 animation_.GetCurrentValue()) + animated_scroll_begin_; |
| 246 | 242 |
| 247 Layout(); | 243 Layout(); |
| 248 SchedulePaint(); | 244 SchedulePaint(); |
| 249 } | 245 } |
| OLD | NEW |