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

Side by Side Diff: third_party/WebKit/Source/core/html/shadow/MediaControls.cpp

Issue 2708193002: Media Controls: cache the minimum width in order to reduce incorrect width usage. (Closed)
Patch Set: Created 3 years, 10 months 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
« no previous file with comments | « third_party/WebKit/LayoutTests/media/controls/buttons-after-reset-expected.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 m_downloadButton.get(), 816 m_downloadButton.get(),
817 m_timeline.get(), 817 m_timeline.get(),
818 m_muteButton.get(), 818 m_muteButton.get(),
819 m_volumeSlider.get(), 819 m_volumeSlider.get(),
820 m_toggleClosedCaptionsButton.get(), 820 m_toggleClosedCaptionsButton.get(),
821 m_castButton.get(), 821 m_castButton.get(),
822 m_currentTimeDisplay.get(), 822 m_currentTimeDisplay.get(),
823 m_durationDisplay.get(), 823 m_durationDisplay.get(),
824 }; 824 };
825 825
826 int usedWidth = 0;
827
828 // TODO(mlamouri): we need a more dynamic way to find out the width of an 826 // TODO(mlamouri): we need a more dynamic way to find out the width of an
829 // element. 827 // element.
830 const int sliderMargin = 36; // Sliders have 18px margin on each side. 828 const int sliderMargin = 36; // Sliders have 18px margin on each side.
831 829
832 // Assume that all controls require 48px, unless we can get the computed
833 // style for the play button. Since the play button or overflow is always
834 // shown, one of the two buttons should be available the first time we're
835 // called after layout. This will
836 // also be the first time we have m_panelWidth!=0, so it won't matter if
837 // we get this wrong before that.
838 int minimumWidth = 48;
839 if (m_playButton->layoutObject() && m_playButton->layoutObject()->style()) {
840 const ComputedStyle* style = m_playButton->layoutObject()->style();
841 minimumWidth = ceil(style->width().pixels() / style->effectiveZoom());
842 } else if (m_overflowMenu->layoutObject() &&
843 m_overflowMenu->layoutObject()->style()) {
844 const ComputedStyle* style = m_overflowMenu->layoutObject()->style();
845 minimumWidth = ceil(style->width().pixels() / style->effectiveZoom());
846 }
847
848 if (!m_panelWidth) { 830 if (!m_panelWidth) {
849 // No layout yet -- hide everything, then make them show up later. 831 // No layout yet -- hide everything, then make them show up later.
850 // This prevents the wrong controls from being shown briefly 832 // This prevents the wrong controls from being shown briefly
851 // immediately after the first layout and paint, but before we have 833 // immediately after the first layout and paint, but before we have
852 // a chance to revise them. 834 // a chance to revise them.
853 for (MediaControlElement* element : elements) { 835 for (MediaControlElement* element : elements) {
854 if (element) 836 if (element)
855 element->setDoesFit(false); 837 element->setDoesFit(false);
856 } 838 }
857 return; 839 return;
858 } 840 }
859 841
842 // Assume that all controls require 48px, unless we can get the computed
843 // style for a button. The minimumWidth is recorded and re-use for future
844 // MediaControls instances and future calls to this method given that at the
845 // moment the controls button width is per plataform.
846 // TODO(mlamouri): improve the mechanism without bandaid.
847 static int minimumWidth = 48;
848 if (m_playButton->layoutObject() && m_playButton->layoutObject()->style()) {
849 const ComputedStyle* style = m_playButton->layoutObject()->style();
850 minimumWidth = ceil(style->width().pixels() / style->effectiveZoom());
851 } else if (m_overflowMenu->layoutObject() &&
852 m_overflowMenu->layoutObject()->style()) {
853 const ComputedStyle* style = m_overflowMenu->layoutObject()->style();
854 minimumWidth = ceil(style->width().pixels() / style->effectiveZoom());
855 }
856
860 // Insert an overflow menu. However, if we see that the overflow menu 857 // Insert an overflow menu. However, if we see that the overflow menu
861 // doesn't end up containing at least two elements, we will not display it 858 // doesn't end up containing at least two elements, we will not display it
862 // but instead make place for the first element that was dropped. 859 // but instead make place for the first element that was dropped.
863 m_overflowMenu->setDoesFit(true); 860 m_overflowMenu->setDoesFit(true);
864 m_overflowMenu->setIsWanted(true); 861 m_overflowMenu->setIsWanted(true);
865 usedWidth = minimumWidth; 862 int usedWidth = minimumWidth;
866 863
867 std::list<MediaControlElement*> overflowElements; 864 std::list<MediaControlElement*> overflowElements;
868 MediaControlElement* firstDisplacedElement = nullptr; 865 MediaControlElement* firstDisplacedElement = nullptr;
869 // For each control that fits, enable it in order of decreasing priority. 866 // For each control that fits, enable it in order of decreasing priority.
870 for (MediaControlElement* element : elements) { 867 for (MediaControlElement* element : elements) {
871 if (!element) 868 if (!element)
872 continue; 869 continue;
873 int width = minimumWidth; 870 int width = minimumWidth;
874 if ((element == m_timeline.get()) || (element == m_volumeSlider.get())) 871 if ((element == m_timeline.get()) || (element == m_volumeSlider.get()))
875 width += sliderMargin; 872 width += sliderMargin;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 visitor->trace(m_overflowList); 969 visitor->trace(m_overflowList);
973 visitor->trace(m_castButton); 970 visitor->trace(m_castButton);
974 visitor->trace(m_overlayCastButton); 971 visitor->trace(m_overlayCastButton);
975 visitor->trace(m_mediaEventListener); 972 visitor->trace(m_mediaEventListener);
976 visitor->trace(m_windowEventListener); 973 visitor->trace(m_windowEventListener);
977 visitor->trace(m_orientationLockDelegate); 974 visitor->trace(m_orientationLockDelegate);
978 HTMLDivElement::trace(visitor); 975 HTMLDivElement::trace(visitor);
979 } 976 }
980 977
981 } // namespace blink 978 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/media/controls/buttons-after-reset-expected.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698