| 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 "views/controls/tabbed_pane/native_tabbed_pane_win.h" | 5 #include "views/controls/tabbed_pane/native_tabbed_pane_win.h" |
| 6 | 6 |
| 7 #include <vssym32.h> | 7 #include <vssym32.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 DISALLOW_COPY_AND_ASSIGN(TabBackground); | 46 DISALLOW_COPY_AND_ASSIGN(TabBackground); |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 // Custom layout manager that takes care of sizing and displaying the tab pages. | 49 // Custom layout manager that takes care of sizing and displaying the tab pages. |
| 50 class TabLayout : public LayoutManager { | 50 class TabLayout : public LayoutManager { |
| 51 public: | 51 public: |
| 52 TabLayout() {} | 52 TabLayout() {} |
| 53 | 53 |
| 54 // Switches to the tab page identified by the given index. | 54 // Switches to the tab page identified by the given index. |
| 55 void SwitchToPage(View* host, View* page) { | 55 void SwitchToPage(View* host, View* page) { |
| 56 for (int i = 0; i < host->GetChildViewCount(); ++i) { | 56 for (size_t i = 0; i < host->child_count(); ++i) { |
| 57 View* child = host->GetChildViewAt(i); | 57 View* child = host->GetChildViewAt(i); |
| 58 // The child might not have been laid out yet. | 58 // The child might not have been laid out yet. |
| 59 if (child == page) | 59 if (child == page) |
| 60 child->SetBoundsRect(host->GetLocalBounds()); | 60 child->SetBoundsRect(host->GetLocalBounds()); |
| 61 child->SetVisible(child == page); | 61 child->SetVisible(child == page); |
| 62 } | 62 } |
| 63 | 63 |
| 64 FocusManager* focus_manager = page->GetFocusManager(); | 64 FocusManager* focus_manager = page->GetFocusManager(); |
| 65 DCHECK(focus_manager); | 65 DCHECK(focus_manager); |
| 66 View* focused_view = focus_manager->GetFocusedView(); | 66 View* focused_view = focus_manager->GetFocusedView(); |
| 67 if (focused_view && host->IsParentOf(focused_view) && | 67 if (focused_view && host->Contains(focused_view) && |
| 68 !page->IsParentOf(focused_view)) | 68 !page->Contains(focused_view)) |
| 69 focus_manager->SetFocusedView(page); | 69 focus_manager->SetFocusedView(page); |
| 70 } | 70 } |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 // LayoutManager overrides: | 73 // LayoutManager overrides: |
| 74 virtual void Layout(View* host) { | 74 virtual void Layout(View* host) { |
| 75 gfx::Rect bounds(host->GetLocalBounds()); | 75 gfx::Rect bounds(host->GetLocalBounds()); |
| 76 for (int i = 0; i < host->GetChildViewCount(); ++i) { | 76 for (size_t i = 0; i < host->child_count(); ++i) { |
| 77 View* child = host->GetChildViewAt(i); | 77 View* child = host->GetChildViewAt(i); |
| 78 // We only layout visible children, since it may be expensive. | 78 // We only layout visible children, since it may be expensive. |
| 79 if (child->IsVisible() && child->bounds() != bounds) | 79 if (child->IsVisible() && child->bounds() != bounds) |
| 80 child->SetBoundsRect(bounds); | 80 child->SetBoundsRect(bounds); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 virtual gfx::Size GetPreferredSize(View* host) { | 84 virtual gfx::Size GetPreferredSize(View* host) { |
| 85 // First, query the preferred sizes to determine a good width. | 85 // First, query the preferred sizes to determine a good width. |
| 86 int width = 0; | 86 int width = 0; |
| 87 for (int i = 0; i < host->GetChildViewCount(); ++i) { | 87 for (size_t i = 0; i < host->child_count(); ++i) { |
| 88 View* page = host->GetChildViewAt(i); | 88 View* page = host->GetChildViewAt(i); |
| 89 width = std::max(width, page->GetPreferredSize().width()); | 89 width = std::max(width, page->GetPreferredSize().width()); |
| 90 } | 90 } |
| 91 // After we know the width, decide on the height. | 91 // After we know the width, decide on the height. |
| 92 return gfx::Size(width, GetPreferredHeightForWidth(host, width)); | 92 return gfx::Size(width, GetPreferredHeightForWidth(host, width)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 virtual int GetPreferredHeightForWidth(View* host, int width) { | 95 virtual int GetPreferredHeightForWidth(View* host, int width) { |
| 96 int height = 0; | 96 int height = 0; |
| 97 for (int i = 0; i < host->GetChildViewCount(); ++i) { | 97 for (size_t i = 0; i < host->child_count(); ++i) { |
| 98 View* page = host->GetChildViewAt(i); | 98 View* page = host->GetChildViewAt(i); |
| 99 height = std::max(height, page->GetHeightForWidth(width)); | 99 height = std::max(height, page->GetHeightForWidth(width)); |
| 100 } | 100 } |
| 101 return height; | 101 return height; |
| 102 } | 102 } |
| 103 | 103 |
| 104 DISALLOW_COPY_AND_ASSIGN(TabLayout); | 104 DISALLOW_COPY_AND_ASSIGN(TabLayout); |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 //////////////////////////////////////////////////////////////////////////////// | 107 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 //////////////////////////////////////////////////////////////////////////////// | 393 //////////////////////////////////////////////////////////////////////////////// |
| 394 // NativeTabbedPaneWrapper, public: | 394 // NativeTabbedPaneWrapper, public: |
| 395 | 395 |
| 396 // static | 396 // static |
| 397 NativeTabbedPaneWrapper* NativeTabbedPaneWrapper::CreateNativeWrapper( | 397 NativeTabbedPaneWrapper* NativeTabbedPaneWrapper::CreateNativeWrapper( |
| 398 TabbedPane* tabbed_pane) { | 398 TabbedPane* tabbed_pane) { |
| 399 return new NativeTabbedPaneWin(tabbed_pane); | 399 return new NativeTabbedPaneWin(tabbed_pane); |
| 400 } | 400 } |
| 401 | 401 |
| 402 } // namespace views | 402 } // namespace views |
| OLD | NEW |