| 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/ui/views/frame/browser_view.h" | 5 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 6 | 6 |
| 7 #if defined(TOOLKIT_USES_GTK) | 7 #if defined(TOOLKIT_USES_GTK) |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 /////////////////////////////////////////////////////////////////////////////// | 247 /////////////////////////////////////////////////////////////////////////////// |
| 248 // ResizeCorner, private: | 248 // ResizeCorner, private: |
| 249 | 249 |
| 250 class ResizeCorner : public views::View { | 250 class ResizeCorner : public views::View { |
| 251 public: | 251 public: |
| 252 ResizeCorner() { | 252 ResizeCorner() { |
| 253 EnableCanvasFlippingForRTLUI(true); | 253 EnableCanvasFlippingForRTLUI(true); |
| 254 } | 254 } |
| 255 | 255 |
| 256 virtual void OnPaint(gfx::Canvas* canvas) { | 256 virtual void OnPaint(gfx::Canvas* canvas) { |
| 257 views::Window* window = GetWindow(); | 257 views::Widget* widget = GetWidget(); |
| 258 if (!window || (window->IsMaximized() || window->IsFullscreen())) | 258 if (!widget || (widget->IsMaximized() || widget->IsFullscreen())) |
| 259 return; | 259 return; |
| 260 | 260 |
| 261 SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetBitmapNamed( | 261 SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 262 IDR_TEXTAREA_RESIZER); | 262 IDR_TEXTAREA_RESIZER); |
| 263 bitmap->buildMipMap(false); | 263 bitmap->buildMipMap(false); |
| 264 canvas->DrawBitmapInt(*bitmap, width() - bitmap->width(), | 264 canvas->DrawBitmapInt(*bitmap, width() - bitmap->width(), |
| 265 height() - bitmap->height()); | 265 height() - bitmap->height()); |
| 266 } | 266 } |
| 267 | 267 |
| 268 static gfx::Size GetSize() { | 268 static gfx::Size GetSize() { |
| 269 // This is disabled until we find what makes us slower when we let | 269 // This is disabled until we find what makes us slower when we let |
| 270 // WebKit know that we have a resizer rect... | 270 // WebKit know that we have a resizer rect... |
| 271 // int scrollbar_thickness = gfx::scrollbar_size(); | 271 // int scrollbar_thickness = gfx::scrollbar_size(); |
| 272 // return gfx::Size(scrollbar_thickness, scrollbar_thickness); | 272 // return gfx::Size(scrollbar_thickness, scrollbar_thickness); |
| 273 return gfx::Size(); | 273 return gfx::Size(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 virtual gfx::Size GetPreferredSize() { | 276 virtual gfx::Size GetPreferredSize() { |
| 277 views::Window* window = GetWindow(); | 277 views::Widget* widget = GetWidget(); |
| 278 return (!window || window->IsMaximized() || window->IsFullscreen()) ? | 278 return (!widget || widget->IsMaximized() || widget->IsFullscreen()) ? |
| 279 gfx::Size() : GetSize(); | 279 gfx::Size() : GetSize(); |
| 280 } | 280 } |
| 281 | 281 |
| 282 virtual void Layout() { | 282 virtual void Layout() { |
| 283 if (parent()) { | 283 if (parent()) { |
| 284 gfx::Size ps = GetPreferredSize(); | 284 gfx::Size ps = GetPreferredSize(); |
| 285 // No need to handle Right to left text direction here, | 285 // No need to handle Right to left text direction here, |
| 286 // our parent must take care of it for us... | 286 // our parent must take care of it for us... |
| 287 // TODO(alekseys): fix it. | 287 // TODO(alekseys): fix it. |
| 288 SetBounds(parent()->width() - ps.width(), | 288 SetBounds(parent()->width() - ps.width(), |
| 289 parent()->height() - ps.height(), ps.width(), ps.height()); | 289 parent()->height() - ps.height(), ps.width(), ps.height()); |
| 290 } | 290 } |
| 291 } | 291 } |
| 292 | 292 |
| 293 private: | 293 private: |
| 294 // Returns the NativeWindowWin we're displayed in. Returns NULL if we're not | |
| 295 // currently in a window. | |
| 296 views::Window* GetWindow() { | |
| 297 views::Widget* widget = GetWidget(); | |
| 298 return widget ? widget->GetContainingWindow() : NULL; | |
| 299 } | |
| 300 | |
| 301 DISALLOW_COPY_AND_ASSIGN(ResizeCorner); | 294 DISALLOW_COPY_AND_ASSIGN(ResizeCorner); |
| 302 }; | 295 }; |
| 303 | 296 |
| 304 /////////////////////////////////////////////////////////////////////////////// | 297 /////////////////////////////////////////////////////////////////////////////// |
| 305 // BrowserView, public: | 298 // BrowserView, public: |
| 306 | 299 |
| 307 BrowserView::BrowserView(Browser* browser) | 300 BrowserView::BrowserView(Browser* browser) |
| 308 : views::ClientView(NULL, NULL), | 301 : views::ClientView(NULL, NULL), |
| 309 last_focused_view_storage_id_( | 302 last_focused_view_storage_id_( |
| 310 views::ViewStorage::GetInstance()->CreateStorageID()), | 303 views::ViewStorage::GetInstance()->CreateStorageID()), |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 LoadingAnimationCallback(); | 734 LoadingAnimationCallback(); |
| 742 } | 735 } |
| 743 } | 736 } |
| 744 } | 737 } |
| 745 | 738 |
| 746 void BrowserView::SetStarredState(bool is_starred) { | 739 void BrowserView::SetStarredState(bool is_starred) { |
| 747 GetLocationBarView()->SetStarToggled(is_starred); | 740 GetLocationBarView()->SetStarToggled(is_starred); |
| 748 } | 741 } |
| 749 | 742 |
| 750 gfx::Rect BrowserView::GetRestoredBounds() const { | 743 gfx::Rect BrowserView::GetRestoredBounds() const { |
| 751 return frame_->GetNormalBounds(); | 744 return frame_->GetRestoredBounds(); |
| 752 } | 745 } |
| 753 | 746 |
| 754 gfx::Rect BrowserView::GetBounds() const { | 747 gfx::Rect BrowserView::GetBounds() const { |
| 755 return frame_->GetBounds(); | 748 return frame_->GetWindowScreenBounds(); |
| 756 } | 749 } |
| 757 | 750 |
| 758 bool BrowserView::IsMaximized() const { | 751 bool BrowserView::IsMaximized() const { |
| 759 return frame_->IsMaximized(); | 752 return frame_->IsMaximized(); |
| 760 } | 753 } |
| 761 | 754 |
| 762 void BrowserView::SetFullscreen(bool fullscreen) { | 755 void BrowserView::SetFullscreen(bool fullscreen) { |
| 763 if (IsFullscreen() == fullscreen) | 756 if (IsFullscreen() == fullscreen) |
| 764 return; // Nothing to do. | 757 return; // Nothing to do. |
| 765 | 758 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 #if defined(OS_WIN) | 985 #if defined(OS_WIN) |
| 993 DefaultSearchView::Show(tab_contents, template_url, template_url_service); | 986 DefaultSearchView::Show(tab_contents, template_url, template_url_service); |
| 994 #else | 987 #else |
| 995 // TODO(levin): Implement for other platforms. Right now this is behind | 988 // TODO(levin): Implement for other platforms. Right now this is behind |
| 996 // a command line flag which is off. http://crbug.com/38475 | 989 // a command line flag which is off. http://crbug.com/38475 |
| 997 #endif | 990 #endif |
| 998 } | 991 } |
| 999 | 992 |
| 1000 void BrowserView::ConfirmAddSearchProvider(const TemplateURL* template_url, | 993 void BrowserView::ConfirmAddSearchProvider(const TemplateURL* template_url, |
| 1001 Profile* profile) { | 994 Profile* profile) { |
| 1002 browser::EditSearchEngine(GetWindow()->GetNativeWindow(), template_url, NULL, | 995 browser::EditSearchEngine(GetWidget()->GetNativeWindow(), template_url, NULL, |
| 1003 profile); | 996 profile); |
| 1004 } | 997 } |
| 1005 | 998 |
| 1006 void BrowserView::ToggleBookmarkBar() { | 999 void BrowserView::ToggleBookmarkBar() { |
| 1007 bookmark_utils::ToggleWhenVisible(browser_->profile()); | 1000 bookmark_utils::ToggleWhenVisible(browser_->profile()); |
| 1008 } | 1001 } |
| 1009 | 1002 |
| 1010 void BrowserView::ShowAboutChromeDialog() { | 1003 void BrowserView::ShowAboutChromeDialog() { |
| 1011 DoShowAboutChromeDialog(); | 1004 DoShowAboutChromeDialog(); |
| 1012 } | 1005 } |
| 1013 | 1006 |
| 1014 views::Window* BrowserView::DoShowAboutChromeDialog() { | 1007 views::Window* BrowserView::DoShowAboutChromeDialog() { |
| 1015 return browser::ShowAboutChromeView(GetWindow()->GetNativeWindow(), | 1008 return browser::ShowAboutChromeView(GetWidget()->GetNativeWindow(), |
| 1016 browser_->profile()); | 1009 browser_->profile()); |
| 1017 } | 1010 } |
| 1018 | 1011 |
| 1019 void BrowserView::ShowUpdateChromeDialog() { | 1012 void BrowserView::ShowUpdateChromeDialog() { |
| 1020 UpdateRecommendedMessageBox::ShowMessageBox(GetWindow()->GetNativeWindow()); | 1013 UpdateRecommendedMessageBox::ShowMessageBox(GetWidget()->GetNativeWindow()); |
| 1021 } | 1014 } |
| 1022 | 1015 |
| 1023 void BrowserView::ShowCompactLocationBarUnderSelectedTab() { | 1016 void BrowserView::ShowCompactLocationBarUnderSelectedTab() { |
| 1024 if (!UseCompactNavigationBar()) | 1017 if (!UseCompactNavigationBar()) |
| 1025 return; | 1018 return; |
| 1026 compact_location_bar_view_host_->UpdateOnTabChange(browser()->active_index(), | 1019 compact_location_bar_view_host_->UpdateOnTabChange(browser()->active_index(), |
| 1027 true); | 1020 true); |
| 1028 } | 1021 } |
| 1029 | 1022 |
| 1030 void BrowserView::ShowTaskManager() { | 1023 void BrowserView::ShowTaskManager() { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 } | 1117 } |
| 1125 | 1118 |
| 1126 void BrowserView::TabContentsFocused(TabContents* tab_contents) { | 1119 void BrowserView::TabContentsFocused(TabContents* tab_contents) { |
| 1127 contents_container_->TabContentsFocused(tab_contents); | 1120 contents_container_->TabContentsFocused(tab_contents); |
| 1128 } | 1121 } |
| 1129 | 1122 |
| 1130 void BrowserView::ShowPageInfo(Profile* profile, | 1123 void BrowserView::ShowPageInfo(Profile* profile, |
| 1131 const GURL& url, | 1124 const GURL& url, |
| 1132 const NavigationEntry::SSLStatus& ssl, | 1125 const NavigationEntry::SSLStatus& ssl, |
| 1133 bool show_history) { | 1126 bool show_history) { |
| 1134 gfx::NativeWindow parent = GetWindow()->GetNativeWindow(); | 1127 gfx::NativeWindow parent = GetWidget()->GetNativeWindow(); |
| 1135 | 1128 |
| 1136 browser::ShowPageInfoBubble(parent, profile, url, ssl, show_history); | 1129 browser::ShowPageInfoBubble(parent, profile, url, ssl, show_history); |
| 1137 } | 1130 } |
| 1138 | 1131 |
| 1139 void BrowserView::ShowAppMenu() { | 1132 void BrowserView::ShowAppMenu() { |
| 1140 // TODO(mad): find out how to add this to compact nav view. | 1133 // TODO(mad): find out how to add this to compact nav view. |
| 1141 toolbar_->app_menu()->Activate(); | 1134 toolbar_->app_menu()->Activate(); |
| 1142 } | 1135 } |
| 1143 | 1136 |
| 1144 bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | 1137 bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1552 } | 1545 } |
| 1553 | 1546 |
| 1554 bool BrowserView::ShouldShowWindowIcon() const { | 1547 bool BrowserView::ShouldShowWindowIcon() const { |
| 1555 return browser_->SupportsWindowFeature(Browser::FEATURE_TITLEBAR); | 1548 return browser_->SupportsWindowFeature(Browser::FEATURE_TITLEBAR); |
| 1556 } | 1549 } |
| 1557 | 1550 |
| 1558 bool BrowserView::ExecuteWindowsCommand(int command_id) { | 1551 bool BrowserView::ExecuteWindowsCommand(int command_id) { |
| 1559 // This function handles WM_SYSCOMMAND, WM_APPCOMMAND, and WM_COMMAND. | 1552 // This function handles WM_SYSCOMMAND, WM_APPCOMMAND, and WM_COMMAND. |
| 1560 #if defined(OS_WIN) | 1553 #if defined(OS_WIN) |
| 1561 if (command_id == IDC_DEBUG_FRAME_TOGGLE) | 1554 if (command_id == IDC_DEBUG_FRAME_TOGGLE) |
| 1562 GetWindow()->DebugToggleFrameType(); | 1555 GetWidget()->DebugToggleFrameType(); |
| 1563 #endif | 1556 #endif |
| 1564 // Translate WM_APPCOMMAND command ids into a command id that the browser | 1557 // Translate WM_APPCOMMAND command ids into a command id that the browser |
| 1565 // knows how to handle. | 1558 // knows how to handle. |
| 1566 int command_id_from_app_command = GetCommandIDForAppCommandID(command_id); | 1559 int command_id_from_app_command = GetCommandIDForAppCommandID(command_id); |
| 1567 if (command_id_from_app_command != -1) | 1560 if (command_id_from_app_command != -1) |
| 1568 command_id = command_id_from_app_command; | 1561 command_id = command_id_from_app_command; |
| 1569 | 1562 |
| 1570 return browser_->ExecuteCommandIfEnabled(command_id); | 1563 return browser_->ExecuteCommandIfEnabled(command_id); |
| 1571 } | 1564 } |
| 1572 | 1565 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1626 | 1619 |
| 1627 bool BrowserView::GetSavedMaximizedState(bool* maximized) const { | 1620 bool BrowserView::GetSavedMaximizedState(bool* maximized) const { |
| 1628 *maximized = browser_->GetSavedMaximizedState(); | 1621 *maximized = browser_->GetSavedMaximizedState(); |
| 1629 return true; | 1622 return true; |
| 1630 } | 1623 } |
| 1631 | 1624 |
| 1632 views::View* BrowserView::GetContentsView() { | 1625 views::View* BrowserView::GetContentsView() { |
| 1633 return contents_container_; | 1626 return contents_container_; |
| 1634 } | 1627 } |
| 1635 | 1628 |
| 1636 views::ClientView* BrowserView::CreateClientView(views::Window* window) { | 1629 views::ClientView* BrowserView::CreateClientView(views::Widget* widget) { |
| 1637 set_window(window); | |
| 1638 return this; | 1630 return this; |
| 1639 } | 1631 } |
| 1640 | 1632 |
| 1641 void BrowserView::OnWindowActivationChanged(bool active) { | 1633 void BrowserView::OnWindowActivationChanged(bool active) { |
| 1642 if (active) { | 1634 if (active) { |
| 1643 BrowserList::SetLastActive(browser_.get()); | 1635 BrowserList::SetLastActive(browser_.get()); |
| 1644 browser_->OnWindowActivated(); | 1636 browser_->OnWindowActivated(); |
| 1645 } | 1637 } |
| 1646 } | 1638 } |
| 1647 | 1639 |
| (...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2559 contents_container_->ChangeTabContents(new_contents->tab_contents()); | 2551 contents_container_->ChangeTabContents(new_contents->tab_contents()); |
| 2560 UpdateSidebarForContents(new_contents); | 2552 UpdateSidebarForContents(new_contents); |
| 2561 | 2553 |
| 2562 UpdateDevToolsForContents(new_contents); | 2554 UpdateDevToolsForContents(new_contents); |
| 2563 // TODO(beng): This should be called automatically by ChangeTabContents, but I | 2555 // TODO(beng): This should be called automatically by ChangeTabContents, but I |
| 2564 // am striving for parity now rather than cleanliness. This is | 2556 // am striving for parity now rather than cleanliness. This is |
| 2565 // required to make features like Duplicate Tab, Undo Close Tab, | 2557 // required to make features like Duplicate Tab, Undo Close Tab, |
| 2566 // etc not result in sad tab. | 2558 // etc not result in sad tab. |
| 2567 new_contents->tab_contents()->DidBecomeSelected(); | 2559 new_contents->tab_contents()->DidBecomeSelected(); |
| 2568 if (BrowserList::GetLastActive() == browser_ && | 2560 if (BrowserList::GetLastActive() == browser_ && |
| 2569 !browser_->tabstrip_model()->closing_all() && GetWindow()->IsVisible()) { | 2561 !browser_->tabstrip_model()->closing_all() && GetWidget()->IsVisible()) { |
| 2570 // We only restore focus if our window is visible, to avoid invoking blur | 2562 // We only restore focus if our window is visible, to avoid invoking blur |
| 2571 // handlers when we are eventually shown. | 2563 // handlers when we are eventually shown. |
| 2572 new_contents->view()->RestoreFocus(); | 2564 new_contents->view()->RestoreFocus(); |
| 2573 } | 2565 } |
| 2574 | 2566 |
| 2575 // Update all the UI bits. | 2567 // Update all the UI bits. |
| 2576 UpdateTitleBar(); | 2568 UpdateTitleBar(); |
| 2577 // No need to update Toolbar because it's already updated in | 2569 // No need to update Toolbar because it's already updated in |
| 2578 // browser.cc. | 2570 // browser.cc. |
| 2579 } | 2571 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2594 } | 2586 } |
| 2595 } | 2587 } |
| 2596 | 2588 |
| 2597 #if !defined(OS_CHROMEOS) | 2589 #if !defined(OS_CHROMEOS) |
| 2598 // static | 2590 // static |
| 2599 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { | 2591 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { |
| 2600 // Create the view and the frame. The frame will attach itself via the view | 2592 // Create the view and the frame. The frame will attach itself via the view |
| 2601 // so we don't need to do anything with the pointer. | 2593 // so we don't need to do anything with the pointer. |
| 2602 BrowserView* view = new BrowserView(browser); | 2594 BrowserView* view = new BrowserView(browser); |
| 2603 (new BrowserFrame(view))->InitBrowserFrame(); | 2595 (new BrowserFrame(view))->InitBrowserFrame(); |
| 2604 view->GetWindow()->non_client_view()->SetAccessibleName( | 2596 view->GetWidget()->non_client_view()->SetAccessibleName( |
| 2605 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | 2597 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
| 2606 return view; | 2598 return view; |
| 2607 } | 2599 } |
| 2608 #endif | 2600 #endif |
| 2609 | 2601 |
| 2610 // static | 2602 // static |
| 2611 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { | 2603 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { |
| 2612 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); | 2604 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); |
| 2613 } | 2605 } |
| OLD | NEW |