OLD | NEW |
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 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 m_downloadButton.get(), | 815 m_downloadButton.get(), |
816 m_timeline.get(), | 816 m_timeline.get(), |
817 m_muteButton.get(), | 817 m_muteButton.get(), |
818 m_volumeSlider.get(), | 818 m_volumeSlider.get(), |
819 m_toggleClosedCaptionsButton.get(), | 819 m_toggleClosedCaptionsButton.get(), |
820 m_castButton.get(), | 820 m_castButton.get(), |
821 m_currentTimeDisplay.get(), | 821 m_currentTimeDisplay.get(), |
822 m_durationDisplay.get(), | 822 m_durationDisplay.get(), |
823 }; | 823 }; |
824 | 824 |
825 int usedWidth = 0; | |
826 | |
827 // TODO(mlamouri): we need a more dynamic way to find out the width of an | 825 // TODO(mlamouri): we need a more dynamic way to find out the width of an |
828 // element. | 826 // element. |
829 const int sliderMargin = 36; // Sliders have 18px margin on each side. | 827 const int sliderMargin = 36; // Sliders have 18px margin on each side. |
830 | 828 |
831 // Assume that all controls require 48px, unless we can get the computed | |
832 // style for the play button. Since the play button or overflow is always | |
833 // shown, one of the two buttons should be available the first time we're | |
834 // called after layout. This will | |
835 // also be the first time we have m_panelWidth!=0, so it won't matter if | |
836 // we get this wrong before that. | |
837 int minimumWidth = 48; | |
838 if (m_playButton->layoutObject() && m_playButton->layoutObject()->style()) { | |
839 const ComputedStyle* style = m_playButton->layoutObject()->style(); | |
840 minimumWidth = ceil(style->width().pixels() / style->effectiveZoom()); | |
841 } else if (m_overflowMenu->layoutObject() && | |
842 m_overflowMenu->layoutObject()->style()) { | |
843 const ComputedStyle* style = m_overflowMenu->layoutObject()->style(); | |
844 minimumWidth = ceil(style->width().pixels() / style->effectiveZoom()); | |
845 } | |
846 | |
847 if (!m_panelWidth) { | 829 if (!m_panelWidth) { |
848 // No layout yet -- hide everything, then make them show up later. | 830 // No layout yet -- hide everything, then make them show up later. |
849 // This prevents the wrong controls from being shown briefly | 831 // This prevents the wrong controls from being shown briefly |
850 // immediately after the first layout and paint, but before we have | 832 // immediately after the first layout and paint, but before we have |
851 // a chance to revise them. | 833 // a chance to revise them. |
852 for (MediaControlElement* element : elements) { | 834 for (MediaControlElement* element : elements) { |
853 if (element) | 835 if (element) |
854 element->setDoesFit(false); | 836 element->setDoesFit(false); |
855 } | 837 } |
856 return; | 838 return; |
857 } | 839 } |
858 | 840 |
| 841 // Assume that all controls require 48px, unless we can get the computed |
| 842 // style for a button. The minimumWidth is recorded and re-use for future |
| 843 // MediaControls instances and future calls to this method given that at the |
| 844 // moment the controls button width is per plataform. |
| 845 // TODO(mlamouri): improve the mechanism without bandaid. |
| 846 static int minimumWidth = 48; |
| 847 if (m_playButton->layoutObject() && m_playButton->layoutObject()->style()) { |
| 848 const ComputedStyle* style = m_playButton->layoutObject()->style(); |
| 849 minimumWidth = ceil(style->width().pixels() / style->effectiveZoom()); |
| 850 } else if (m_overflowMenu->layoutObject() && |
| 851 m_overflowMenu->layoutObject()->style()) { |
| 852 const ComputedStyle* style = m_overflowMenu->layoutObject()->style(); |
| 853 minimumWidth = ceil(style->width().pixels() / style->effectiveZoom()); |
| 854 } |
| 855 |
859 // Insert an overflow menu. However, if we see that the overflow menu | 856 // Insert an overflow menu. However, if we see that the overflow menu |
860 // doesn't end up containing at least two elements, we will not display it | 857 // doesn't end up containing at least two elements, we will not display it |
861 // but instead make place for the first element that was dropped. | 858 // but instead make place for the first element that was dropped. |
862 m_overflowMenu->setDoesFit(true); | 859 m_overflowMenu->setDoesFit(true); |
863 m_overflowMenu->setIsWanted(true); | 860 m_overflowMenu->setIsWanted(true); |
864 usedWidth = minimumWidth; | 861 int usedWidth = minimumWidth; |
865 | 862 |
866 std::list<MediaControlElement*> overflowElements; | 863 std::list<MediaControlElement*> overflowElements; |
867 MediaControlElement* firstDisplacedElement = nullptr; | 864 MediaControlElement* firstDisplacedElement = nullptr; |
868 // For each control that fits, enable it in order of decreasing priority. | 865 // For each control that fits, enable it in order of decreasing priority. |
869 for (MediaControlElement* element : elements) { | 866 for (MediaControlElement* element : elements) { |
870 if (!element) | 867 if (!element) |
871 continue; | 868 continue; |
872 int width = minimumWidth; | 869 int width = minimumWidth; |
873 if ((element == m_timeline.get()) || (element == m_volumeSlider.get())) | 870 if ((element == m_timeline.get()) || (element == m_volumeSlider.get())) |
874 width += sliderMargin; | 871 width += sliderMargin; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 visitor->trace(m_overflowList); | 968 visitor->trace(m_overflowList); |
972 visitor->trace(m_castButton); | 969 visitor->trace(m_castButton); |
973 visitor->trace(m_overlayCastButton); | 970 visitor->trace(m_overlayCastButton); |
974 visitor->trace(m_mediaEventListener); | 971 visitor->trace(m_mediaEventListener); |
975 visitor->trace(m_windowEventListener); | 972 visitor->trace(m_windowEventListener); |
976 visitor->trace(m_orientationLockDelegate); | 973 visitor->trace(m_orientationLockDelegate); |
977 HTMLDivElement::trace(visitor); | 974 HTMLDivElement::trace(visitor); |
978 } | 975 } |
979 | 976 |
980 } // namespace blink | 977 } // namespace blink |
OLD | NEW |