Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/constrained_window_views.h" | 5 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
| 12 #include "chrome/browser/platform_util.h" | 12 #include "chrome/browser/platform_util.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/themes/theme_properties.h" | 14 #include "chrome/browser/themes/theme_properties.h" |
| 15 #include "chrome/browser/ui/browser_finder.h" | |
| 15 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 16 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 16 #include "chrome/browser/ui/views/frame/browser_view.h" | 17 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 17 #include "chrome/browser/ui/views/theme_image_mapper.h" | 18 #include "chrome/browser/ui/views/theme_image_mapper.h" |
| 18 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
| 19 #include "components/web_modal/web_contents_modal_dialog_host.h" | 20 #include "components/web_modal/web_contents_modal_dialog_host.h" |
| 20 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 21 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 21 #include "content/public/browser/navigation_controller.h" | 22 #include "content/public/browser/navigation_controller.h" |
| 22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/browser/web_contents_view.h" | 24 #include "content/public/browser/web_contents_view.h" |
| 24 #include "grit/chromium_strings.h" | 25 #include "grit/chromium_strings.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 gfx::Size size = target_widget_->GetWindowBoundsInScreen().size(); | 120 gfx::Size size = target_widget_->GetWindowBoundsInScreen().size(); |
| 120 gfx::Point position = host_->GetDialogPosition(size); | 121 gfx::Point position = host_->GetDialogPosition(size); |
| 121 views::Border* border = | 122 views::Border* border = |
| 122 target_widget_->non_client_view()->frame_view()->border(); | 123 target_widget_->non_client_view()->frame_view()->border(); |
| 123 // Border may be null during widget initialization. | 124 // Border may be null during widget initialization. |
| 124 if (border) { | 125 if (border) { |
| 125 // Align the first row of pixels inside the border. This is the apparent | 126 // Align the first row of pixels inside the border. This is the apparent |
| 126 // top of the dialog. | 127 // top of the dialog. |
| 127 position.set_y(position.y() - border->GetInsets().top()); | 128 position.set_y(position.y() - border->GetInsets().top()); |
| 128 } | 129 } |
| 130 | |
| 131 if (target_widget_->is_top_level()) | |
| 132 position += views::Widget::GetWidgetForNativeView(host_->GetHostView())-> | |
| 133 GetClientAreaBoundsInScreen().OffsetFromOrigin(); | |
| 134 | |
| 129 target_widget_->SetBounds(gfx::Rect(position, size)); | 135 target_widget_->SetBounds(gfx::Rect(position, size)); |
| 130 } | 136 } |
| 131 | 137 |
| 132 private: | 138 private: |
| 133 WebContentsModalDialogHost* host_; | 139 WebContentsModalDialogHost* host_; |
| 134 views::Widget* target_widget_; | 140 views::Widget* target_widget_; |
| 135 const char* const native_window_property_; | 141 const char* const native_window_property_; |
| 136 | 142 |
| 137 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogHostObserverViews); | 143 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogHostObserverViews); |
| 138 }; | 144 }; |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 673 | 679 |
| 674 if (dialog_host_observer) { | 680 if (dialog_host_observer) { |
| 675 dialog_host_observer->OnPositionRequiresUpdate(); | 681 dialog_host_observer->OnPositionRequiresUpdate(); |
| 676 dialog->SetNativeWindowProperty(kWebContentsModalDialogHostObserverViewsKey, | 682 dialog->SetNativeWindowProperty(kWebContentsModalDialogHostObserverViewsKey, |
| 677 dialog_host_observer); | 683 dialog_host_observer); |
| 678 } | 684 } |
| 679 | 685 |
| 680 return dialog; | 686 return dialog; |
| 681 } | 687 } |
| 682 | 688 |
| 689 views::Widget* CreateBrowserModalDialogViews(views::DialogDelegate* dialog, | |
| 690 gfx::NativeWindow parent) { | |
| 691 views::Widget* widget = | |
| 692 views::DialogDelegate::CreateDialogWidget(dialog, NULL, parent); | |
| 693 if (!dialog->UseNewStyleForThisDialog()) | |
| 694 return widget; | |
| 695 | |
| 696 // Get the browser dialog management and hosting components from |parent|. | |
| 697 Browser* browser = chrome::FindBrowserWithWindow(parent); | |
| 698 if (browser) { | |
|
Mike Wittman
2013/06/07 02:38:03
How about DCHECK(browser)? Wouldn't invoking this
msw
2013/06/07 17:51:13
I'm not so sure, take a look at the parent wrangli
| |
| 699 ChromeWebModalDialogManagerDelegate* manager = browser; | |
| 700 WebContentsModalDialogHost* host = manager->GetWebContentsModalDialogHost(); | |
| 701 DCHECK_EQ(parent, host->GetHostView()); | |
| 702 WebContentsModalDialogHostObserver* dialog_host_observer = | |
| 703 new WebContentsModalDialogHostObserverViews( | |
| 704 host, widget, kWebContentsModalDialogHostObserverViewsKey); | |
| 705 dialog_host_observer->OnPositionRequiresUpdate(); | |
| 706 } | |
| 707 return widget; | |
| 708 } | |
| 709 | |
| 683 views::NonClientFrameView* CreateConstrainedStyleNonClientFrameView( | 710 views::NonClientFrameView* CreateConstrainedStyleNonClientFrameView( |
| 684 views::Widget* widget, | 711 views::Widget* widget, |
| 685 content::BrowserContext* browser_context) { | 712 content::BrowserContext* browser_context) { |
| 686 if (views::DialogDelegate::UseNewStyle()) { | 713 if (views::DialogDelegate::UseNewStyle()) { |
| 687 #if defined(USE_AURA) | 714 #if defined(USE_AURA) |
| 688 const bool force_opaque_border = false; | 715 const bool force_opaque_border = false; |
| 689 #else | 716 #else |
| 690 const bool force_opaque_border = true; | 717 const bool force_opaque_border = true; |
| 691 #endif | 718 #endif |
| 692 return views::DialogDelegate::CreateNewStyleFrameView(widget, | 719 return views::DialogDelegate::CreateNewStyleFrameView(widget, |
| 693 force_opaque_border); | 720 force_opaque_border); |
| 694 } | 721 } |
| 695 #if defined(USE_ASH) | 722 #if defined(USE_ASH) |
| 696 ConstrainedWindowFrameViewAsh* frame = new ConstrainedWindowFrameViewAsh; | 723 ConstrainedWindowFrameViewAsh* frame = new ConstrainedWindowFrameViewAsh; |
| 697 frame->Init(widget); | 724 frame->Init(widget); |
| 698 return frame; | 725 return frame; |
| 699 #endif | 726 #endif |
| 700 return new ConstrainedWindowFrameView(widget, | 727 return new ConstrainedWindowFrameView(widget, |
| 701 browser_context->IsOffTheRecord()); | 728 browser_context->IsOffTheRecord()); |
| 702 } | 729 } |
| OLD | NEW |