OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/controls/scroll_view.h" | 5 #include "views/controls/scroll_view.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "views/controls/scrollbar/native_scroll_bar.h" | 8 #include "views/controls/scrollbar/native_scroll_bar.h" |
9 #include "views/widget/root_view.h" | 9 #include "views/widget/root_view.h" |
10 | 10 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 vert_sb_->SetController(this); | 96 vert_sb_->SetController(this); |
97 if (resize_corner_) | 97 if (resize_corner_) |
98 resize_corner_->SetVisible(false); | 98 resize_corner_->SetVisible(false); |
99 } | 99 } |
100 | 100 |
101 // Make sure that a single scrollbar is created and visible as needed | 101 // Make sure that a single scrollbar is created and visible as needed |
102 void ScrollView::SetControlVisibility(View* control, bool should_show) { | 102 void ScrollView::SetControlVisibility(View* control, bool should_show) { |
103 if (!control) | 103 if (!control) |
104 return; | 104 return; |
105 if (should_show) { | 105 if (should_show) { |
106 if (!control->IsVisible()) { | 106 if (!control->visible()) { |
107 AddChildView(control); | 107 AddChildView(control); |
108 control->SetVisible(true); | 108 control->SetVisible(true); |
109 } | 109 } |
110 } else { | 110 } else { |
111 RemoveChildView(control); | 111 RemoveChildView(control); |
112 control->SetVisible(false); | 112 control->SetVisible(false); |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 void ScrollView::ComputeScrollBarsVisibility(const gfx::Size& vp_size, | 116 void ScrollView::ComputeScrollBarsVisibility(const gfx::Size& vp_size, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 // This is no op if bounds are the same | 251 // This is no op if bounds are the same |
252 contents_->SetBounds(-x, -y, contents_->width(), contents_->height()); | 252 contents_->SetBounds(-x, -y, contents_->width(), contents_->height()); |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 gfx::Rect ScrollView::GetVisibleRect() const { | 256 gfx::Rect ScrollView::GetVisibleRect() const { |
257 if (!contents_) | 257 if (!contents_) |
258 return gfx::Rect(); | 258 return gfx::Rect(); |
259 | 259 |
260 const int x = | 260 const int x = |
261 (horiz_sb_ && horiz_sb_->IsVisible()) ? horiz_sb_->GetPosition() : 0; | 261 (horiz_sb_ && horiz_sb_->visible()) ? horiz_sb_->GetPosition() : 0; |
262 const int y = | 262 const int y = |
263 (vert_sb_ && vert_sb_->IsVisible()) ? vert_sb_->GetPosition() : 0; | 263 (vert_sb_ && vert_sb_->visible()) ? vert_sb_->GetPosition() : 0; |
264 return gfx::Rect(x, y, viewport_->width(), viewport_->height()); | 264 return gfx::Rect(x, y, viewport_->width(), viewport_->height()); |
265 } | 265 } |
266 | 266 |
267 void ScrollView::ScrollContentsRegionToBeVisible(const gfx::Rect& rect) { | 267 void ScrollView::ScrollContentsRegionToBeVisible(const gfx::Rect& rect) { |
268 if (!contents_ || ((!horiz_sb_ || !horiz_sb_->IsVisible()) && | 268 if (!contents_ || ((!horiz_sb_ || !horiz_sb_->visible()) && |
269 (!vert_sb_ || !vert_sb_->IsVisible()))) { | 269 (!vert_sb_ || !vert_sb_->visible()))) { |
270 return; | 270 return; |
271 } | 271 } |
272 | 272 |
273 // Figure out the maximums for this scroll view. | 273 // Figure out the maximums for this scroll view. |
274 const int contents_max_x = | 274 const int contents_max_x = |
275 std::max(viewport_->width(), contents_->width()); | 275 std::max(viewport_->width(), contents_->width()); |
276 const int contents_max_y = | 276 const int contents_max_y = |
277 std::max(viewport_->height(), contents_->height()); | 277 std::max(viewport_->height(), contents_->height()); |
278 | 278 |
279 // Make sure x and y are within the bounds of [0,contents_max_*]. | 279 // Make sure x and y are within the bounds of [0,contents_max_*]. |
(...skipping 29 matching lines...) Expand all Loading... |
309 contents_->SetX(-new_x); | 309 contents_->SetX(-new_x); |
310 contents_->SetY(-new_y); | 310 contents_->SetY(-new_y); |
311 UpdateScrollBarPositions(); | 311 UpdateScrollBarPositions(); |
312 } | 312 } |
313 | 313 |
314 void ScrollView::UpdateScrollBarPositions() { | 314 void ScrollView::UpdateScrollBarPositions() { |
315 if (!contents_) { | 315 if (!contents_) { |
316 return; | 316 return; |
317 } | 317 } |
318 | 318 |
319 if (horiz_sb_->IsVisible()) { | 319 if (horiz_sb_->visible()) { |
320 int vw = viewport_->width(); | 320 int vw = viewport_->width(); |
321 int cw = contents_->width(); | 321 int cw = contents_->width(); |
322 int origin = contents_->x(); | 322 int origin = contents_->x(); |
323 horiz_sb_->Update(vw, cw, -origin); | 323 horiz_sb_->Update(vw, cw, -origin); |
324 } | 324 } |
325 if (vert_sb_->IsVisible()) { | 325 if (vert_sb_->visible()) { |
326 int vh = viewport_->height(); | 326 int vh = viewport_->height(); |
327 int ch = contents_->height(); | 327 int ch = contents_->height(); |
328 int origin = contents_->y(); | 328 int origin = contents_->y(); |
329 vert_sb_->Update(vh, ch, -origin); | 329 vert_sb_->Update(vh, ch, -origin); |
330 } | 330 } |
331 } | 331 } |
332 | 332 |
333 // TODO(ACW): We should really use ScrollWindowEx as needed | 333 // TODO(ACW): We should really use ScrollWindowEx as needed |
334 void ScrollView::ScrollToPosition(ScrollBar* source, int position) { | 334 void ScrollView::ScrollToPosition(ScrollBar* source, int position) { |
335 if (!contents_) | 335 if (!contents_) |
336 return; | 336 return; |
337 | 337 |
338 if (source == horiz_sb_ && horiz_sb_->IsVisible()) { | 338 if (source == horiz_sb_ && horiz_sb_->visible()) { |
339 int vw = viewport_->width(); | 339 int vw = viewport_->width(); |
340 int cw = contents_->width(); | 340 int cw = contents_->width(); |
341 int origin = contents_->x(); | 341 int origin = contents_->x(); |
342 if (-origin != position) { | 342 if (-origin != position) { |
343 int max_pos = std::max(0, cw - vw); | 343 int max_pos = std::max(0, cw - vw); |
344 if (position < 0) | 344 if (position < 0) |
345 position = 0; | 345 position = 0; |
346 else if (position > max_pos) | 346 else if (position > max_pos) |
347 position = max_pos; | 347 position = max_pos; |
348 contents_->SetX(-position); | 348 contents_->SetX(-position); |
349 contents_->SchedulePaintInRect(contents_->GetVisibleBounds()); | 349 contents_->SchedulePaintInRect(contents_->GetVisibleBounds()); |
350 } | 350 } |
351 } else if (source == vert_sb_ && vert_sb_->IsVisible()) { | 351 } else if (source == vert_sb_ && vert_sb_->visible()) { |
352 int vh = viewport_->height(); | 352 int vh = viewport_->height(); |
353 int ch = contents_->height(); | 353 int ch = contents_->height(); |
354 int origin = contents_->y(); | 354 int origin = contents_->y(); |
355 if (-origin != position) { | 355 if (-origin != position) { |
356 int max_pos = std::max(0, ch - vh); | 356 int max_pos = std::max(0, ch - vh); |
357 if (position < 0) | 357 if (position < 0) |
358 position = 0; | 358 position = 0; |
359 else if (position > max_pos) | 359 else if (position > max_pos) |
360 position = max_pos; | 360 position = max_pos; |
361 contents_->SetY(-position); | 361 contents_->SetY(-position); |
(...skipping 18 matching lines...) Expand all Loading... |
380 // No view, or the view didn't return a valid amount. | 380 // No view, or the view didn't return a valid amount. |
381 if (is_page) | 381 if (is_page) |
382 return is_horizontal ? viewport_->width() : viewport_->height(); | 382 return is_horizontal ? viewport_->width() : viewport_->height(); |
383 return is_horizontal ? viewport_->width() / 5 : viewport_->height() / 5; | 383 return is_horizontal ? viewport_->width() / 5 : viewport_->height() / 5; |
384 } | 384 } |
385 | 385 |
386 bool ScrollView::OnKeyPressed(const KeyEvent& event) { | 386 bool ScrollView::OnKeyPressed(const KeyEvent& event) { |
387 bool processed = false; | 387 bool processed = false; |
388 | 388 |
389 // Give vertical scrollbar priority | 389 // Give vertical scrollbar priority |
390 if (vert_sb_->IsVisible()) { | 390 if (vert_sb_->visible()) { |
391 processed = vert_sb_->OnKeyPressed(event); | 391 processed = vert_sb_->OnKeyPressed(event); |
392 } | 392 } |
393 | 393 |
394 if (!processed && horiz_sb_->IsVisible()) { | 394 if (!processed && horiz_sb_->visible()) { |
395 processed = horiz_sb_->OnKeyPressed(event); | 395 processed = horiz_sb_->OnKeyPressed(event); |
396 } | 396 } |
397 return processed; | 397 return processed; |
398 } | 398 } |
399 | 399 |
400 bool ScrollView::OnMouseWheel(const MouseWheelEvent& e) { | 400 bool ScrollView::OnMouseWheel(const MouseWheelEvent& e) { |
401 bool processed = false; | 401 bool processed = false; |
402 // Give vertical scrollbar priority | 402 // Give vertical scrollbar priority |
403 if (vert_sb_->IsVisible()) { | 403 if (vert_sb_->visible()) { |
404 processed = vert_sb_->OnMouseWheel(e); | 404 processed = vert_sb_->OnMouseWheel(e); |
405 } | 405 } |
406 if (!processed && horiz_sb_->IsVisible()) { | 406 if (!processed && horiz_sb_->visible()) { |
407 processed = horiz_sb_->OnMouseWheel(e); | 407 processed = horiz_sb_->OnMouseWheel(e); |
408 } | 408 } |
409 return processed; | 409 return processed; |
410 } | 410 } |
411 | 411 |
412 std::string ScrollView::GetClassName() const { | 412 std::string ScrollView::GetClassName() const { |
413 return kViewClassName; | 413 return kViewClassName; |
414 } | 414 } |
415 | 415 |
416 int ScrollView::GetScrollBarWidth() const { | 416 int ScrollView::GetScrollBarWidth() const { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 | 488 |
489 VariableRowHeightScrollHelper::RowInfo | 489 VariableRowHeightScrollHelper::RowInfo |
490 FixedRowHeightScrollHelper::GetRowInfo(int y) { | 490 FixedRowHeightScrollHelper::GetRowInfo(int y) { |
491 if (y < top_margin_) | 491 if (y < top_margin_) |
492 return RowInfo(0, top_margin_); | 492 return RowInfo(0, top_margin_); |
493 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, | 493 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, |
494 row_height_); | 494 row_height_); |
495 } | 495 } |
496 | 496 |
497 } // namespace views | 497 } // namespace views |
OLD | NEW |