| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/frame/browser_view.h" | 5 #include "chrome/browser/views/frame/browser_view.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_version_info.h" | 8 #include "base/file_version_info.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // How long do we wait before we consider a window hung (in ms). | 86 // How long do we wait before we consider a window hung (in ms). |
| 87 static const int kDefaultPluginMessageResponseTimeout = 30000; | 87 static const int kDefaultPluginMessageResponseTimeout = 30000; |
| 88 // The number of milliseconds between loading animation frames. | 88 // The number of milliseconds between loading animation frames. |
| 89 static const int kLoadingAnimationFrameTimeMs = 30; | 89 static const int kLoadingAnimationFrameTimeMs = 30; |
| 90 // The amount of space we expect the window border to take up. | 90 // The amount of space we expect the window border to take up. |
| 91 static const int kWindowBorderWidth = 5; | 91 static const int kWindowBorderWidth = 5; |
| 92 | 92 |
| 93 // If not -1, windows are shown with this state. | 93 // If not -1, windows are shown with this state. |
| 94 static int explicit_show_state = -1; | 94 static int explicit_show_state = -1; |
| 95 | 95 |
| 96 // Returned from BrowserView::GetClassName. |
| 97 static const char kBrowserViewClassName[] = "browser/views/BrowserView"; |
| 98 |
| 96 static const struct { | 99 static const struct { |
| 97 bool separator; | 100 bool separator; |
| 98 int command; | 101 int command; |
| 99 int label; | 102 int label; |
| 100 } kMenuLayout[] = { | 103 } kMenuLayout[] = { |
| 101 { true, 0, 0 }, | 104 { true, 0, 0 }, |
| 102 { false, IDC_TASK_MANAGER, IDS_TASK_MANAGER }, | 105 { false, IDC_TASK_MANAGER, IDS_TASK_MANAGER }, |
| 103 { true, 0, 0 }, | 106 { true, 0, 0 }, |
| 104 { false, IDC_ENCODING_MENU, IDS_ENCODING_MENU }, | 107 { false, IDC_ENCODING_MENU, IDS_ENCODING_MENU }, |
| 105 { false, IDC_ZOOM_MENU, IDS_ZOOM_MENU }, | 108 { false, IDC_ZOOM_MENU, IDS_ZOOM_MENU }, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 119 { false, IDC_RELOAD, IDS_APP_MENU_RELOAD }, | 122 { false, IDC_RELOAD, IDS_APP_MENU_RELOAD }, |
| 120 { false, IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD }, | 123 { false, IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD }, |
| 121 { false, IDC_BACK, IDS_CONTENT_CONTEXT_BACK } | 124 { false, IDC_BACK, IDS_CONTENT_CONTEXT_BACK } |
| 122 }; | 125 }; |
| 123 | 126 |
| 124 /////////////////////////////////////////////////////////////////////////////// | 127 /////////////////////////////////////////////////////////////////////////////// |
| 125 // ResizeCorner, private: | 128 // ResizeCorner, private: |
| 126 | 129 |
| 127 class ResizeCorner : public views::View { | 130 class ResizeCorner : public views::View { |
| 128 public: | 131 public: |
| 129 explicit ResizeCorner(const BrowserView* parent) | 132 ResizeCorner() { } |
| 130 : parent_(parent) { | |
| 131 } | |
| 132 | 133 |
| 133 virtual void Paint(ChromeCanvas* canvas) { | 134 virtual void Paint(ChromeCanvas* canvas) { |
| 134 if (parent_ && !parent_->CanCurrentlyResize()) | 135 BrowserView* browser = GetBrowserView(); |
| 136 if (browser && !browser->CanCurrentlyResize()) |
| 135 return; | 137 return; |
| 136 | 138 |
| 137 SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetBitmapNamed( | 139 SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 138 IDR_TEXTAREA_RESIZER); | 140 IDR_TEXTAREA_RESIZER); |
| 139 bitmap->buildMipMap(false); | 141 bitmap->buildMipMap(false); |
| 140 bool rtl_dir = (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT); | 142 bool rtl_dir = (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT); |
| 141 if (rtl_dir) { | 143 if (rtl_dir) { |
| 142 canvas->TranslateInt(width(), 0); | 144 canvas->TranslateInt(width(), 0); |
| 143 canvas->ScaleInt(-1, 1); | 145 canvas->ScaleInt(-1, 1); |
| 144 canvas->save(); | 146 canvas->save(); |
| 145 } | 147 } |
| 146 canvas->DrawBitmapInt(*bitmap, width() - bitmap->width(), | 148 canvas->DrawBitmapInt(*bitmap, width() - bitmap->width(), |
| 147 height() - bitmap->height()); | 149 height() - bitmap->height()); |
| 148 if (rtl_dir) | 150 if (rtl_dir) |
| 149 canvas->restore(); | 151 canvas->restore(); |
| 150 } | 152 } |
| 151 | 153 |
| 152 static gfx::Size GetSize() { | 154 static gfx::Size GetSize() { |
| 153 // This is disabled until we find what makes us slower when we let | 155 // This is disabled until we find what makes us slower when we let |
| 154 // WebKit know that we have a resizer rect... | 156 // WebKit know that we have a resizer rect... |
| 155 // return gfx::Size(views::NativeScrollBar::GetVerticalScrollBarWidth(), | 157 // return gfx::Size(views::NativeScrollBar::GetVerticalScrollBarWidth(), |
| 156 // views::NativeScrollBar::GetHorizontalScrollBarHeight()); | 158 // views::NativeScrollBar::GetHorizontalScrollBarHeight()); |
| 157 return gfx::Size(); | 159 return gfx::Size(); |
| 158 } | 160 } |
| 159 | 161 |
| 160 virtual gfx::Size GetPreferredSize() { | 162 virtual gfx::Size GetPreferredSize() { |
| 161 return (parent_ && !parent_->CanCurrentlyResize()) ? | 163 BrowserView* browser = GetBrowserView(); |
| 164 return (browser && !browser->CanCurrentlyResize()) ? |
| 162 gfx::Size() : GetSize(); | 165 gfx::Size() : GetSize(); |
| 163 } | 166 } |
| 164 | 167 |
| 165 virtual void Layout() { | 168 virtual void Layout() { |
| 166 views::View* parent_view = GetParent(); | 169 views::View* parent_view = GetParent(); |
| 167 if (parent_view) { | 170 if (parent_view) { |
| 168 gfx::Size ps = GetPreferredSize(); | 171 gfx::Size ps = GetPreferredSize(); |
| 169 // No need to handle Right to left text direction here, | 172 // No need to handle Right to left text direction here, |
| 170 // our parent must take care of it for us... | 173 // our parent must take care of it for us... |
| 171 SetBounds(parent_view->width() - ps.width(), | 174 SetBounds(parent_view->width() - ps.width(), |
| 172 parent_view->height() - ps.height(), ps.width(), ps.height()); | 175 parent_view->height() - ps.height(), ps.width(), ps.height()); |
| 173 } | 176 } |
| 174 } | 177 } |
| 175 | 178 |
| 176 private: | 179 private: |
| 177 const BrowserView* parent_; | 180 // Returns the BrowserView we're displayed in. Returns NULL if we're not |
| 181 // currently in a browser view. |
| 182 BrowserView* GetBrowserView() { |
| 183 View* browser = GetAncestorWithClassName(kBrowserViewClassName); |
| 184 return browser ? static_cast<BrowserView*>(browser) : NULL; |
| 185 } |
| 186 |
| 178 DISALLOW_COPY_AND_ASSIGN(ResizeCorner); | 187 DISALLOW_COPY_AND_ASSIGN(ResizeCorner); |
| 179 }; | 188 }; |
| 180 | 189 |
| 181 | 190 |
| 182 /////////////////////////////////////////////////////////////////////////////// | 191 /////////////////////////////////////////////////////////////////////////////// |
| 183 // BrowserView, public: | 192 // BrowserView, public: |
| 184 | 193 |
| 185 // static | 194 // static |
| 186 void BrowserView::SetShowState(int state) { | 195 void BrowserView::SetShowState(int state) { |
| 187 explicit_show_state = state; | 196 explicit_show_state = state; |
| (...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1178 if (bv_bounds.Contains(point)) | 1187 if (bv_bounds.Contains(point)) |
| 1179 return HTNOWHERE; | 1188 return HTNOWHERE; |
| 1180 | 1189 |
| 1181 // If the point is somewhere else, delegate to the default implementation. | 1190 // If the point is somewhere else, delegate to the default implementation. |
| 1182 return views::ClientView::NonClientHitTest(point); | 1191 return views::ClientView::NonClientHitTest(point); |
| 1183 } | 1192 } |
| 1184 | 1193 |
| 1185 /////////////////////////////////////////////////////////////////////////////// | 1194 /////////////////////////////////////////////////////////////////////////////// |
| 1186 // BrowserView, views::View overrides: | 1195 // BrowserView, views::View overrides: |
| 1187 | 1196 |
| 1197 std::string BrowserView::GetClassName() const { |
| 1198 return kBrowserViewClassName; |
| 1199 } |
| 1200 |
| 1188 void BrowserView::Layout() { | 1201 void BrowserView::Layout() { |
| 1189 int top = LayoutTabStrip(); | 1202 int top = LayoutTabStrip(); |
| 1190 top = LayoutToolbar(top); | 1203 top = LayoutToolbar(top); |
| 1191 top = LayoutBookmarkAndInfoBars(top); | 1204 top = LayoutBookmarkAndInfoBars(top); |
| 1192 int bottom = LayoutDownloadShelf(); | 1205 int bottom = LayoutDownloadShelf(); |
| 1193 LayoutTabContents(top, bottom); | 1206 LayoutTabContents(top, bottom); |
| 1194 // This must be done _after_ we lay out the TabContents since this code calls | 1207 // This must be done _after_ we lay out the TabContents since this code calls |
| 1195 // back into us to find the bounding box the find bar must be laid out within, | 1208 // back into us to find the bounding box the find bar must be laid out within, |
| 1196 // and that code depends on the TabContentsContainer's bounds being up to | 1209 // and that code depends on the TabContentsContainer's bounds being up to |
| 1197 // date. | 1210 // date. |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 // InfoBarContainer, DownloadShelfView and TabContents and this | 1451 // InfoBarContainer, DownloadShelfView and TabContents and this |
| 1439 // view is sorted out. | 1452 // view is sorted out. |
| 1440 return true; | 1453 return true; |
| 1441 } | 1454 } |
| 1442 | 1455 |
| 1443 bool BrowserView::MaybeShowDownloadShelf(TabContents* contents) { | 1456 bool BrowserView::MaybeShowDownloadShelf(TabContents* contents) { |
| 1444 views::View* new_shelf = NULL; | 1457 views::View* new_shelf = NULL; |
| 1445 if (contents && contents->IsDownloadShelfVisible()) { | 1458 if (contents && contents->IsDownloadShelfVisible()) { |
| 1446 new_shelf = static_cast<DownloadShelfView*>(contents->GetDownloadShelf()); | 1459 new_shelf = static_cast<DownloadShelfView*>(contents->GetDownloadShelf()); |
| 1447 if (new_shelf != active_download_shelf_) | 1460 if (new_shelf != active_download_shelf_) |
| 1448 new_shelf->AddChildView(new ResizeCorner(this)); | 1461 new_shelf->AddChildView(new ResizeCorner()); |
| 1449 } | 1462 } |
| 1450 return UpdateChildViewAndLayout(new_shelf, &active_download_shelf_); | 1463 return UpdateChildViewAndLayout(new_shelf, &active_download_shelf_); |
| 1451 } | 1464 } |
| 1452 | 1465 |
| 1453 void BrowserView::UpdateUIForContents(TabContents* contents) { | 1466 void BrowserView::UpdateUIForContents(TabContents* contents) { |
| 1454 bool needs_layout = MaybeShowBookmarkBar(contents); | 1467 bool needs_layout = MaybeShowBookmarkBar(contents); |
| 1455 needs_layout |= MaybeShowInfoBar(contents); | 1468 needs_layout |= MaybeShowInfoBar(contents); |
| 1456 needs_layout |= MaybeShowDownloadShelf(contents); | 1469 needs_layout |= MaybeShowDownloadShelf(contents); |
| 1457 if (needs_layout) | 1470 if (needs_layout) |
| 1458 Layout(); | 1471 Layout(); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1656 } | 1669 } |
| 1657 } | 1670 } |
| 1658 | 1671 |
| 1659 // static | 1672 // static |
| 1660 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { | 1673 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { |
| 1661 BrowserView* browser_view = new BrowserView(browser); | 1674 BrowserView* browser_view = new BrowserView(browser); |
| 1662 (new BrowserFrame(browser_view))->Init(); | 1675 (new BrowserFrame(browser_view))->Init(); |
| 1663 return browser_view; | 1676 return browser_view; |
| 1664 } | 1677 } |
| 1665 | 1678 |
| OLD | NEW |