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

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

Issue 2374733002: Media Controls: take into consideration high margin on some elements. (Closed)
Patch Set: rebaseline Created 4 years, 2 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/platform/win/media/video-zoom-controls-expected.txt ('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 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 m_muteButton.get(), 724 m_muteButton.get(),
725 m_volumeSlider.get(), 725 m_volumeSlider.get(),
726 m_toggleClosedCaptionsButton.get(), 726 m_toggleClosedCaptionsButton.get(),
727 m_castButton.get(), 727 m_castButton.get(),
728 m_currentTimeDisplay.get(), 728 m_currentTimeDisplay.get(),
729 m_durationDisplay.get(), 729 m_durationDisplay.get(),
730 }; 730 };
731 731
732 int usedWidth = 0; 732 int usedWidth = 0;
733 733
734 // TODO(mlamouri): we need a more dynamic way to find out the width of an
735 // element.
736 const int sliderMargin = 36; // Sliders have 18px margin on each side.
737
734 // Assume that all controls require 48px, unless we can get the computed 738 // Assume that all controls require 48px, unless we can get the computed
735 // style for the play button. Since the play button or overflow is always 739 // style for the play button. Since the play button or overflow is always
736 // shown, one of the two buttons should be available the first time we're 740 // shown, one of the two buttons should be available the first time we're
737 // called after layout. This will 741 // called after layout. This will
738 // also be the first time we have m_panelWidth!=0, so it won't matter if 742 // also be the first time we have m_panelWidth!=0, so it won't matter if
739 // we get this wrong before that. 743 // we get this wrong before that.
740 int minimumWidth = 48; 744 int minimumWidth = 48;
741 if (m_playButton->layoutObject() && m_playButton->layoutObject()->style()) { 745 if (m_playButton->layoutObject() && m_playButton->layoutObject()->style()) {
742 const ComputedStyle* style = m_playButton->layoutObject()->style(); 746 const ComputedStyle* style = m_playButton->layoutObject()->style();
743 minimumWidth = ceil(style->width().pixels() / style->effectiveZoom()); 747 minimumWidth = ceil(style->width().pixels() / style->effectiveZoom());
(...skipping 21 matching lines...) Expand all
765 m_overflowMenu->setIsWanted(true); 769 m_overflowMenu->setIsWanted(true);
766 usedWidth = minimumWidth; 770 usedWidth = minimumWidth;
767 771
768 std::list<MediaControlElement*> overflowElements; 772 std::list<MediaControlElement*> overflowElements;
769 MediaControlElement* firstDisplacedElement = nullptr; 773 MediaControlElement* firstDisplacedElement = nullptr;
770 // For each control that fits, enable it in order of decreasing priority. 774 // For each control that fits, enable it in order of decreasing priority.
771 bool droppedCastButton = false; 775 bool droppedCastButton = false;
772 for (MediaControlElement* element : elements) { 776 for (MediaControlElement* element : elements) {
773 if (!element) 777 if (!element)
774 continue; 778 continue;
779 int width = minimumWidth;
780 if ((element == m_timeline.get()) || (element == m_volumeSlider.get()))
781 width += sliderMargin;
775 element->shouldShowButtonInOverflowMenu(false); 782 element->shouldShowButtonInOverflowMenu(false);
776 if (element->isWanted()) { 783 if (element->isWanted()) {
777 if (usedWidth + minimumWidth <= m_panelWidth) { 784 if (usedWidth + width <= m_panelWidth) {
778 element->setDoesFit(true); 785 element->setDoesFit(true);
779 usedWidth += minimumWidth; 786 usedWidth += width;
780 } else { 787 } else {
781 element->setDoesFit(false); 788 element->setDoesFit(false);
789 // TODO(mlamouri): we should probably no longer mark the cast
790 // button as dropped, it should appear in the overflow menu.
782 if (element == m_castButton.get()) 791 if (element == m_castButton.get())
783 droppedCastButton = true; 792 droppedCastButton = true;
784 element->shouldShowButtonInOverflowMenu(true); 793 element->shouldShowButtonInOverflowMenu(true);
785 if (element->hasOverflowButton()) 794 if (element->hasOverflowButton())
786 overflowElements.push_front(element); 795 overflowElements.push_front(element);
787 // We want a way to access the first media element that was 796 // We want a way to access the first media element that was
788 // removed. If we don't end up needing an overflow menu, we can 797 // removed. If we don't end up needing an overflow menu, we can
789 // use the space the overflow menu would have taken up to 798 // use the space the overflow menu would have taken up to
790 // instead display that media element. 799 // instead display that media element.
791 if (!element->hasOverflowButton() && !firstDisplacedElement) 800 if (!element->hasOverflowButton() && !firstDisplacedElement)
792 firstDisplacedElement = element; 801 firstDisplacedElement = element;
793 } 802 }
794 } 803 }
795 } 804 }
796 805
797 // If we don't have at least two overflow elements, we will not show the 806 // If we don't have at least two overflow elements, we will not show the
798 // overflow menu. 807 // overflow menu.
799 if (overflowElements.empty()) { 808 if (overflowElements.empty()) {
800 m_overflowMenu->setIsWanted(false); 809 m_overflowMenu->setIsWanted(false);
801 if (firstDisplacedElement) 810 usedWidth -= minimumWidth;
802 firstDisplacedElement->setDoesFit(true); 811 if (firstDisplacedElement) {
812 int width = minimumWidth;
813 if ((firstDisplacedElement == m_timeline.get()) || (firstDisplacedEl ement == m_volumeSlider.get()))
814 width += sliderMargin;
815 if (usedWidth + width <= m_panelWidth)
816 firstDisplacedElement->setDoesFit(true);
817 }
803 } else if (overflowElements.size() == 1) { 818 } else if (overflowElements.size() == 1) {
804 m_overflowMenu->setIsWanted(false); 819 m_overflowMenu->setIsWanted(false);
805 overflowElements.front()->setDoesFit(true); 820 overflowElements.front()->setDoesFit(true);
806 } 821 }
807 822
808 // Special case for cast: if we want a cast button but dropped it, then 823 // Special case for cast: if we want a cast button but dropped it, then
809 // show the overlay cast button instead. 824 // show the overlay cast button instead.
810 if (m_castButton->isWanted()) { 825 if (m_castButton->isWanted()) {
811 if (droppedCastButton) 826 if (droppedCastButton)
812 m_overlayCastButton->tryShowOverlay(); 827 m_overlayCastButton->tryShowOverlay();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 visitor->trace(m_enclosure); 886 visitor->trace(m_enclosure);
872 visitor->trace(m_textTrackList); 887 visitor->trace(m_textTrackList);
873 visitor->trace(m_overflowMenu); 888 visitor->trace(m_overflowMenu);
874 visitor->trace(m_overflowList); 889 visitor->trace(m_overflowList);
875 visitor->trace(m_castButton); 890 visitor->trace(m_castButton);
876 visitor->trace(m_overlayCastButton); 891 visitor->trace(m_overlayCastButton);
877 HTMLDivElement::trace(visitor); 892 HTMLDivElement::trace(visitor);
878 } 893 }
879 894
880 } // namespace blink 895 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/platform/win/media/video-zoom-controls-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698