Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: chrome/browser/views/frame/browser_view.cc

Issue 10896: Re-do the way browser windows are shown:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/command_line.h" 5 #include "base/command_line.h"
6 6
7 #include "chrome/browser/views/frame/browser_view.h" 7 #include "chrome/browser/views/frame/browser_view.h"
8 8
9 #include "chrome/app/chrome_dll_resource.h" 9 #include "chrome/app/chrome_dll_resource.h"
10 #include "chrome/app/theme/theme_resources.h" 10 #include "chrome/app/theme/theme_resources.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 116 }
117 117
118 BrowserView::~BrowserView() { 118 BrowserView::~BrowserView() {
119 browser_->tabstrip_model()->RemoveObserver(this); 119 browser_->tabstrip_model()->RemoveObserver(this);
120 120
121 // Stop hung plugin monitoring. 121 // Stop hung plugin monitoring.
122 ticker_.Stop(); 122 ticker_.Stop();
123 ticker_.UnregisterTickHandler(&hung_window_detector_); 123 ticker_.UnregisterTickHandler(&hung_window_detector_);
124 } 124 }
125 125
126 int BrowserView::GetShowState() const {
127 STARTUPINFO si = {0};
128 si.cb = sizeof(si);
129 si.dwFlags = STARTF_USESHOWWINDOW;
130 GetStartupInfo(&si);
131 return si.wShowWindow;
132 }
133
126 void BrowserView::WindowMoved() { 134 void BrowserView::WindowMoved() {
127 // Cancel any tabstrip animations, some of them may be invalidated by the 135 // Cancel any tabstrip animations, some of them may be invalidated by the
128 // window being repositioned. 136 // window being repositioned.
129 // Comment out for one cycle to see if this fixes dist tests. 137 // Comment out for one cycle to see if this fixes dist tests.
130 //tabstrip_->DestroyDragController(); 138 //tabstrip_->DestroyDragController();
131 139
132 status_bubble_->Reposition(); 140 status_bubble_->Reposition();
133 141
134 // Close the omnibox popup, if any. 142 // Close the omnibox popup, if any.
135 if (GetLocationBarView()) 143 if (GetLocationBarView())
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 EnablePersonalization(CommandLine().HasSwitch(switches::kEnableP13n)); 321 EnablePersonalization(CommandLine().HasSwitch(switches::kEnableP13n));
314 if (IsPersonalizationEnabled()) { 322 if (IsPersonalizationEnabled()) {
315 personalization_ = Personalization::CreateFramePersonalization( 323 personalization_ = Personalization::CreateFramePersonalization(
316 browser_->profile(), this); 324 browser_->profile(), this);
317 } 325 }
318 #endif 326 #endif
319 327
320 InitSystemMenu(); 328 InitSystemMenu();
321 } 329 }
322 330
323 void BrowserView::Show(int command, bool adjust_to_fit) { 331 void BrowserView::Show() {
324 frame_->GetWindow()->Show(command); 332 // If the window is already visible, just activate it.
333 if (frame_->GetWindow()->IsVisible()) {
334 frame_->GetWindow()->Activate();
335 return;
336 }
337
338 // Setting the focus doesn't work when the window is invisible, so any focus
339 // initialization that happened before this will be lost.
340 //
341 // We really "should" restore the focus whenever the window becomes unhidden,
342 // but I think initializing is the only time where this can happen where
343 // there is some focus change we need to pick up, and this is easier than
344 // plumbing through an un-hide message all the way from the frame.
345 //
346 // If we do find there are cases where we need to restore the focus on show,
347 // that should be added and this should be removed.
348 TabContents* selected_tab_contents = GetSelectedTabContents();
349 if (selected_tab_contents)
350 selected_tab_contents->RestoreFocus();
351
352 frame_->GetWindow()->Show();
353 int show_state = frame_->GetWindow()->GetShowState();
354 if (show_state == SW_SHOWNORMAL || show_state == SW_SHOWMAXIMIZED)
355 frame_->GetWindow()->Activate();
325 } 356 }
326 357
327 void BrowserView::Close() { 358 void BrowserView::Close() {
328 frame_->GetWindow()->Close(); 359 frame_->GetWindow()->Close();
329 } 360 }
330 361
331 void BrowserView::Activate() { 362 void BrowserView::Activate() {
332 frame_->GetWindow()->Activate(); 363 frame_->GetWindow()->Activate();
333 } 364 }
334 365
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 frame_->GetWindow()->UpdateWindowIcon(); 402 frame_->GetWindow()->UpdateWindowIcon();
372 } 403 }
373 404
374 void BrowserView::ValidateThrobber() { 405 void BrowserView::ValidateThrobber() {
375 if (ShouldShowWindowIcon()) { 406 if (ShouldShowWindowIcon()) {
376 TabContents* tab_contents = browser_->GetSelectedTabContents(); 407 TabContents* tab_contents = browser_->GetSelectedTabContents();
377 frame_->UpdateThrobber(tab_contents ? tab_contents->is_loading() : false); 408 frame_->UpdateThrobber(tab_contents ? tab_contents->is_loading() : false);
378 } 409 }
379 } 410 }
380 411
381 gfx::Rect BrowserView::GetNormalBounds() { 412 gfx::Rect BrowserView::GetNormalBounds() const {
382 WINDOWPLACEMENT wp; 413 WINDOWPLACEMENT wp;
383 wp.length = sizeof(wp); 414 wp.length = sizeof(wp);
384 const bool ret = !!GetWindowPlacement(frame_->GetWindow()->GetHWND(), &wp); 415 const bool ret = !!GetWindowPlacement(frame_->GetWindow()->GetHWND(), &wp);
385 DCHECK(ret); 416 DCHECK(ret);
386 return gfx::Rect(wp.rcNormalPosition); 417 return gfx::Rect(wp.rcNormalPosition);
387 } 418 }
388 419
389 bool BrowserView::IsMaximized() { 420 bool BrowserView::IsMaximized() {
390 return frame_->GetWindow()->IsMaximized(); 421 return frame_->GetWindow()->IsMaximized();
391 } 422 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 command_id = command_id_from_app_command; 586 command_id = command_id_from_app_command;
556 587
557 if (browser_->SupportsCommand(command_id)) { 588 if (browser_->SupportsCommand(command_id)) {
558 if (browser_->IsCommandEnabled(command_id)) 589 if (browser_->IsCommandEnabled(command_id))
559 browser_->ExecuteCommand(command_id); 590 browser_->ExecuteCommand(command_id);
560 return true; 591 return true;
561 } 592 }
562 return false; 593 return false;
563 } 594 }
564 595
565 void BrowserView::SaveWindowPosition(const CRect& bounds, 596 void BrowserView::SaveWindowPlacement(const gfx::Rect& bounds,
566 bool maximized, 597 bool maximized,
567 bool always_on_top) { 598 bool always_on_top) {
568 browser_->SaveWindowPosition(gfx::Rect(bounds), maximized); 599 browser_->SaveWindowPlacement(bounds, maximized);
569 } 600 }
570 601
571 bool BrowserView::RestoreWindowPosition(CRect* bounds, 602 bool BrowserView::GetSavedWindowBounds(gfx::Rect* bounds) const {
572 bool* maximized,
573 bool* always_on_top) {
574 DCHECK(bounds && maximized && always_on_top);
575 *always_on_top = false;
576
577 if (browser_->type() == BrowserType::BROWSER) { 603 if (browser_->type() == BrowserType::BROWSER) {
578 // We are a popup window. The value passed in |bounds| represents two 604 // We are a popup window. The value passed in |bounds| represents two
579 // pieces of information: 605 // pieces of information:
580 // - the position of the window, in screen coordinates (outer position). 606 // - the position of the window, in screen coordinates (outer position).
581 // - the size of the content area (inner size). 607 // - the size of the content area (inner size).
582 // We need to use these values to determine the appropriate size and 608 // We need to use these values to determine the appropriate size and
583 // position of the resulting window. 609 // position of the resulting window.
584 if (SupportsWindowFeature(FEATURE_TOOLBAR) || 610 if (SupportsWindowFeature(FEATURE_TOOLBAR) ||
585 SupportsWindowFeature(FEATURE_LOCATIONBAR)) { 611 SupportsWindowFeature(FEATURE_LOCATIONBAR)) {
586 // If we're showing the toolbar, we need to adjust |*bounds| to include 612 // If we're showing the toolbar, we need to adjust |*bounds| to include
587 // its desired height, since the toolbar is considered part of the 613 // its desired height, since the toolbar is considered part of the
588 // window's client area as far as GetWindowBoundsForClientBounds is 614 // window's client area as far as GetWindowBoundsForClientBounds is
589 // concerned... 615 // concerned...
590 bounds->bottom += toolbar_->GetPreferredSize().height(); 616 bounds->set_height(
617 bounds->height() + toolbar_->GetPreferredSize().height());
591 } 618 }
592 619
593 gfx::Rect window_rect = 620 gfx::Rect window_rect = frame_->GetWindowBoundsForClientBounds(*bounds);
594 frame_->GetWindowBoundsForClientBounds(gfx::Rect(*bounds)); 621 window_rect.set_origin(gfx::Point(bounds->x(), bounds->y()));
595 window_rect.set_origin(gfx::Point(bounds->left, bounds->top));
596 622
597 // When we are given x/y coordinates of 0 on a created popup window, 623 // When we are given x/y coordinates of 0 on a created popup window,
598 // assume none were given by the window.open() command. 624 // assume none were given by the window.open() command.
599 if (window_rect.x() == 0 && window_rect.y() == 0) { 625 if (window_rect.x() == 0 && window_rect.y() == 0) {
600 gfx::Point origin = GetNormalBounds().origin(); 626 gfx::Point origin = GetNormalBounds().origin();
601 origin.set_x(origin.x() + kWindowTilePixels); 627 origin.set_x(origin.x() + kWindowTilePixels);
602 origin.set_y(origin.y() + kWindowTilePixels); 628 origin.set_y(origin.y() + kWindowTilePixels);
603 window_rect.set_origin(origin); 629 window_rect.set_origin(origin);
604 } 630 }
605 631
606 *bounds = window_rect.ToRECT(); 632 *bounds = window_rect;
607 *maximized = false;
608 } else { 633 } else {
609 // TODO(beng): (http://b/1317622) Make these functions take gfx::Rects. 634 *bounds = browser_->GetSavedWindowBounds();
610 gfx::Rect b(*bounds);
611 browser_->RestoreWindowPosition(&b, maximized);
612 *bounds = b.ToRECT();
613 } 635 }
614 636
615 // We return true because we can _always_ locate reasonable bounds using the 637 // We return true because we can _always_ locate reasonable bounds using the
616 // WindowSizer, and we don't want to trigger the Window's built-in "size to 638 // WindowSizer, and we don't want to trigger the Window's built-in "size to
617 // default" handling because the browser window has no default preferred 639 // default" handling because the browser window has no default preferred
618 // size. 640 // size.
619 return true; 641 return true;
620 } 642 }
621 643
644 bool BrowserView::GetSavedMaximizedState(bool* maximized) const {
645 *maximized = browser_->GetSavedMaximizedState();
646 return true;
647 }
648
622 void BrowserView::WindowClosing() { 649 void BrowserView::WindowClosing() {
623 } 650 }
624 651
625 views::View* BrowserView::GetContentsView() { 652 views::View* BrowserView::GetContentsView() {
626 return contents_container_; 653 return contents_container_;
627 } 654 }
628 655
629 views::ClientView* BrowserView::CreateClientView(views::Window* window) { 656 views::ClientView* BrowserView::CreateClientView(views::Window* window) {
630 set_window(window); 657 set_window(window);
631 return this; 658 return this;
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 1196
1170 // static 1197 // static
1171 void BrowserView::InitClass() { 1198 void BrowserView::InitClass() {
1172 static bool initialized = false; 1199 static bool initialized = false;
1173 if (!initialized) { 1200 if (!initialized) {
1174 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1201 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1175 default_favicon_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); 1202 default_favicon_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
1176 initialized = true; 1203 initialized = true;
1177 } 1204 }
1178 } 1205 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698