| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 "web/PopupMenuImpl.h" | 5 #include "web/PopupMenuImpl.h" |
| 6 | 6 |
| 7 #include "core/HTMLNames.h" | 7 #include "core/HTMLNames.h" |
| 8 #include "core/css/CSSFontSelector.h" | 8 #include "core/css/CSSFontSelector.h" |
| 9 #include "core/dom/ElementTraversal.h" | 9 #include "core/dom/ElementTraversal.h" |
| 10 #include "core/dom/NodeComputedStyle.h" | 10 #include "core/dom/NodeComputedStyle.h" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 visitor->Trace(owner_element_); | 256 visitor->Trace(owner_element_); |
| 257 PopupMenu::Trace(visitor); | 257 PopupMenu::Trace(visitor); |
| 258 } | 258 } |
| 259 | 259 |
| 260 void PopupMenuImpl::WriteDocument(SharedBuffer* data) { | 260 void PopupMenuImpl::WriteDocument(SharedBuffer* data) { |
| 261 HTMLSelectElement& owner_element = *owner_element_; | 261 HTMLSelectElement& owner_element = *owner_element_; |
| 262 IntRect anchor_rect_in_screen = chrome_client_->ViewportToScreen( | 262 IntRect anchor_rect_in_screen = chrome_client_->ViewportToScreen( |
| 263 owner_element.VisibleBoundsInVisualViewport(), | 263 owner_element.VisibleBoundsInVisualViewport(), |
| 264 owner_element.GetDocument().View()); | 264 owner_element.GetDocument().View()); |
| 265 | 265 |
| 266 float scale_factor = chrome_client_->WindowToViewportScalar(1.f); |
| 266 PagePopupClient::AddString( | 267 PagePopupClient::AddString( |
| 267 "<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", data); | 268 "<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", data); |
| 268 data->Append(Platform::Current()->LoadResource("pickerCommon.css")); | 269 data->Append(Platform::Current()->LoadResource("pickerCommon.css")); |
| 269 data->Append(Platform::Current()->LoadResource("listPicker.css")); | 270 data->Append(Platform::Current()->LoadResource("listPicker.css")); |
| 271 if (!RuntimeEnabledFeatures::forceTallerSelectPopupEnabled()) |
| 272 PagePopupClient::AddString("@media (any-pointer:coarse) {", data); |
| 273 int padding = static_cast<int>(roundf(4 * scale_factor)); |
| 274 int min_height = static_cast<int>(roundf(24 * scale_factor)); |
| 275 PagePopupClient::AddString(String::Format("option, optgroup {" |
| 276 "padding-top: %dpx;" |
| 277 "padding-bottom: %dpx;" |
| 278 "min-height: %dpx;" |
| 279 "display: flex;" |
| 280 "align-items: center;" |
| 281 "}", |
| 282 padding, padding, min_height), |
| 283 data); |
| 284 if (!RuntimeEnabledFeatures::forceTallerSelectPopupEnabled()) { |
| 285 // Closes @media. |
| 286 PagePopupClient::AddString("}", data); |
| 287 } |
| 288 |
| 270 PagePopupClient::AddString( | 289 PagePopupClient::AddString( |
| 271 "</style></head><body><div id=main>Loading...</div><script>\n" | 290 "</style></head><body><div id=main>Loading...</div><script>\n" |
| 272 "window.dialogArguments = {\n", | 291 "window.dialogArguments = {\n", |
| 273 data); | 292 data); |
| 274 AddProperty("selectedIndex", owner_element.SelectedListIndex(), data); | 293 AddProperty("selectedIndex", owner_element.SelectedListIndex(), data); |
| 275 const ComputedStyle* owner_style = owner_element.GetComputedStyle(); | 294 const ComputedStyle* owner_style = owner_element.GetComputedStyle(); |
| 276 ItemIterationContext context(*owner_style, data); | 295 ItemIterationContext context(*owner_style, data); |
| 277 context.SerializeBaseStyle(); | 296 context.SerializeBaseStyle(); |
| 278 PagePopupClient::AddString("children: [\n", data); | 297 PagePopupClient::AddString("children: [\n", data); |
| 279 const HeapVector<Member<HTMLElement>>& items = owner_element.GetListItems(); | 298 const HeapVector<Member<HTMLElement>>& items = owner_element.GetListItems(); |
| 280 for (; context.list_index_ < items.size(); ++context.list_index_) { | 299 for (; context.list_index_ < items.size(); ++context.list_index_) { |
| 281 Element& child = *items[context.list_index_]; | 300 Element& child = *items[context.list_index_]; |
| 282 if (!isHTMLOptGroupElement(child.parentNode())) | 301 if (!isHTMLOptGroupElement(child.parentNode())) |
| 283 context.FinishGroupIfNecessary(); | 302 context.FinishGroupIfNecessary(); |
| 284 if (isHTMLOptionElement(child)) | 303 if (isHTMLOptionElement(child)) |
| 285 AddOption(context, toHTMLOptionElement(child)); | 304 AddOption(context, toHTMLOptionElement(child)); |
| 286 else if (isHTMLOptGroupElement(child)) | 305 else if (isHTMLOptGroupElement(child)) |
| 287 AddOptGroup(context, toHTMLOptGroupElement(child)); | 306 AddOptGroup(context, toHTMLOptGroupElement(child)); |
| 288 else if (isHTMLHRElement(child)) | 307 else if (isHTMLHRElement(child)) |
| 289 AddSeparator(context, toHTMLHRElement(child)); | 308 AddSeparator(context, toHTMLHRElement(child)); |
| 290 } | 309 } |
| 291 context.FinishGroupIfNecessary(); | 310 context.FinishGroupIfNecessary(); |
| 292 PagePopupClient::AddString("],\n", data); | 311 PagePopupClient::AddString("],\n", data); |
| 293 | 312 |
| 294 AddProperty("anchorRectInScreen", anchor_rect_in_screen, data); | 313 AddProperty("anchorRectInScreen", anchor_rect_in_screen, data); |
| 295 float scale_factor = chrome_client_->WindowToViewportScalar(1.f); | |
| 296 AddProperty("zoomFactor", 1, data); | 314 AddProperty("zoomFactor", 1, data); |
| 297 AddProperty("scaleFactor", scale_factor, data); | 315 AddProperty("scaleFactor", scale_factor, data); |
| 298 bool is_rtl = !owner_style->IsLeftToRightDirection(); | 316 bool is_rtl = !owner_style->IsLeftToRightDirection(); |
| 299 AddProperty("isRTL", is_rtl, data); | 317 AddProperty("isRTL", is_rtl, data); |
| 300 AddProperty("paddingStart", | 318 AddProperty("paddingStart", |
| 301 is_rtl ? owner_element.ClientPaddingRight().ToDouble() | 319 is_rtl ? owner_element.ClientPaddingRight().ToDouble() |
| 302 : owner_element.ClientPaddingLeft().ToDouble(), | 320 : owner_element.ClientPaddingLeft().ToDouble(), |
| 303 data); | 321 data); |
| 304 PagePopupClient::AddString("};\n", data); | 322 PagePopupClient::AddString("};\n", data); |
| 305 data->Append(Platform::Current()->LoadResource("pickerCommon.js")); | 323 data->Append(Platform::Current()->LoadResource("pickerCommon.js")); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 } | 576 } |
| 559 | 577 |
| 560 void PopupMenuImpl::DisconnectClient() { | 578 void PopupMenuImpl::DisconnectClient() { |
| 561 owner_element_ = nullptr; | 579 owner_element_ = nullptr; |
| 562 // Cannot be done during finalization, so instead done when the | 580 // Cannot be done during finalization, so instead done when the |
| 563 // layout object is destroyed and disconnected. | 581 // layout object is destroyed and disconnected. |
| 564 Dispose(); | 582 Dispose(); |
| 565 } | 583 } |
| 566 | 584 |
| 567 } // namespace blink | 585 } // namespace blink |
| OLD | NEW |