gpu: Tweak Android WebGL test expectations
[chromium-blink-merge.git] / chrome_frame / turndown_prompt / turndown_prompt_content.cc
blob8b58b50ac76c3bafc17b494fa046167dd01aa4f8
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome_frame/turndown_prompt/turndown_prompt_content.h"
7 #include "base/logging.h"
8 #include "chrome_frame/ready_mode/internal/url_launcher.h"
9 #include "chrome_frame/turndown_prompt/turndown_prompt_window.h"
11 TurndownPromptContent::TurndownPromptContent(
12 UrlLauncher* url_launcher,
13 const base::Closure& uninstall_closure)
14 : url_launcher_(url_launcher),
15 uninstall_closure_(uninstall_closure) {
18 TurndownPromptContent::~TurndownPromptContent() {
19 if (window_ != NULL && window_->IsWindow()) {
20 // The window must discard its ContentFrame pointer at this time.
21 window_->DestroyWindow();
22 window_.reset();
26 bool TurndownPromptContent::InstallInFrame(Frame* frame) {
27 DCHECK(window_ == NULL);
28 DCHECK(url_launcher_ != NULL);
30 // Pass ownership of our url_launcher_ to the window.
31 window_ = TurndownPromptWindow::CreateInstance(
32 frame, url_launcher_.release(), uninstall_closure_);
33 uninstall_closure_.Reset();
35 return window_ != NULL;
38 void TurndownPromptContent::SetDimensions(const RECT& dimensions) {
39 if (window_ != NULL && window_->IsWindow()) {
40 window_->SetWindowPos(HWND_TOP, &dimensions,
41 ::IsRectEmpty(&dimensions) ? SWP_HIDEWINDOW :
42 SWP_SHOWWINDOW);
46 bool GetDialogTemplateDimensions(TurndownPromptWindow* window,
47 RECT* dimensions) {
48 HRSRC resource = ::FindResource(_AtlBaseModule.GetResourceInstance(),
49 MAKEINTRESOURCE(TurndownPromptWindow::IDD),
50 RT_DIALOG);
52 HGLOBAL handle = NULL;
53 DLGTEMPLATE* dlgtemplate = NULL;
54 _DialogSplitHelper::DLGTEMPLATEEX* dlgtemplateex = NULL;
56 if (resource == NULL) {
57 DPLOG(ERROR) << "Failed to find resource for TurndownPromptWindow::IDD";
58 return false;
61 handle = ::LoadResource(_AtlBaseModule.GetResourceInstance(), resource);
63 if (handle == NULL) {
64 DPLOG(ERROR) << "Failed to load resource for TurndownPromptWindow::IDD";
65 return false;
68 dlgtemplate = reinterpret_cast<DLGTEMPLATE*>(::LockResource(handle));
69 if (dlgtemplate == NULL) {
70 DPLOG(ERROR) << "Failed to lock resource for TurndownPromptWindow::IDD";
71 return false;
74 if (!_DialogSplitHelper::IsDialogEx(dlgtemplate)) {
75 DLOG(ERROR) << "Resource TurndownPromptWindow::IDD is not a DLGTEMPLATEEX";
76 return false;
79 dlgtemplateex =
80 reinterpret_cast<_DialogSplitHelper::DLGTEMPLATEEX*>(dlgtemplate);
82 RECT dlgdimensions = {0, 0, dlgtemplateex->cx, dlgtemplateex->cy};
83 if (!window->MapDialogRect(&dlgdimensions)) {
84 DPLOG(ERROR) << "Failure in MapDialogRect";
85 return false;
88 *dimensions = dlgdimensions;
89 return true;
92 size_t TurndownPromptContent::GetDesiredSize(size_t width, size_t height) {
93 DCHECK(window_ != NULL && window_->IsWindow());
95 if (window_ == NULL || !window_->IsWindow()) {
96 return 0;
98 RECT dialog_dimensions = {0, 0, 0, 0};
100 if (GetDialogTemplateDimensions(window_.get(), &dialog_dimensions))
101 return width == 0 ? dialog_dimensions.right : dialog_dimensions.bottom;
102 else
103 return width == 0 ? 0 : 39;