774 newWidth = getIntAttr(HTML.Attribute.WIDTH, -1); |
774 newWidth = getIntAttr(HTML.Attribute.WIDTH, -1); |
775 newHeight = getIntAttr(HTML.Attribute.HEIGHT, -1); |
775 newHeight = getIntAttr(HTML.Attribute.HEIGHT, -1); |
776 |
776 |
777 if (newWidth > 0) { |
777 if (newWidth > 0) { |
778 newState |= WIDTH_FLAG; |
778 newState |= WIDTH_FLAG; |
779 if (newHeight <= 0) { |
|
780 newHeight = newWidth; |
|
781 newState |= HEIGHT_FLAG; |
|
782 } |
|
783 } |
779 } |
784 |
780 |
785 if (newHeight > 0) { |
781 if (newHeight > 0) { |
786 newState |= HEIGHT_FLAG; |
782 newState |= HEIGHT_FLAG; |
787 if (newWidth <= 0) { |
|
788 newWidth = newHeight; |
|
789 newState |= WIDTH_FLAG; |
|
790 } |
|
791 } |
|
792 |
|
793 if (newWidth <= 0) { |
|
794 newWidth = newImage.getWidth(imageObserver); |
|
795 if (newWidth <= 0) { |
|
796 newWidth = DEFAULT_WIDTH; |
|
797 } |
|
798 } |
|
799 |
|
800 if (newHeight <= 0) { |
|
801 newHeight = newImage.getHeight(imageObserver); |
|
802 if (newHeight <= 0) { |
|
803 newHeight = DEFAULT_HEIGHT; |
|
804 } |
|
805 } |
783 } |
806 |
784 |
807 // Make sure the image starts loading: |
785 // Make sure the image starts loading: |
808 if ((newState & (WIDTH_FLAG | HEIGHT_FLAG)) != 0) { |
786 if ((newState & (WIDTH_FLAG | HEIGHT_FLAG)) != 0) { |
809 Toolkit.getDefaultToolkit().prepareImage(newImage, newWidth, |
787 Toolkit.getDefaultToolkit().prepareImage(newImage, newWidth, |
963 if ((flags & ImageObserver.WIDTH) != 0 && !getElement(). |
941 if ((flags & ImageObserver.WIDTH) != 0 && !getElement(). |
964 getAttributes().isDefined(HTML.Attribute.WIDTH)) { |
942 getAttributes().isDefined(HTML.Attribute.WIDTH)) { |
965 changed |= 2; |
943 changed |= 2; |
966 } |
944 } |
967 |
945 |
|
946 /** |
|
947 * If the image properties (height and width) have been loaded, |
|
948 * then figure out if scaling is necessary based on the |
|
949 * specified HTML attributes. |
|
950 */ |
|
951 if (((flags & ImageObserver.HEIGHT) != 0) && |
|
952 ((flags & ImageObserver.WIDTH) != 0)) { |
|
953 double proportion = 0.0; |
|
954 final int specifiedWidth = getIntAttr(HTML.Attribute.WIDTH, -1); |
|
955 final int specifiedHeight = getIntAttr(HTML.Attribute.HEIGHT, -1); |
|
956 /** |
|
957 * If either of the attributes are not specified, then calculate the |
|
958 * proportion for the specified dimension wrt actual value, and then |
|
959 * apply the same proportion to the unspecified dimension as well, |
|
960 * so that the aspect ratio of the image is maintained. |
|
961 */ |
|
962 if (specifiedWidth != -1 ^ specifiedHeight != -1) { |
|
963 if (specifiedWidth <= 0) { |
|
964 proportion = specifiedHeight / ((double)newHeight); |
|
965 newWidth = (int)(proportion * newWidth); |
|
966 } |
|
967 |
|
968 if (specifiedHeight <= 0) { |
|
969 proportion = specifiedWidth / ((double)newWidth); |
|
970 newHeight = (int)(proportion * newHeight); |
|
971 } |
|
972 changed |= 3; |
|
973 } |
|
974 } |
968 synchronized(ImageView.this) { |
975 synchronized(ImageView.this) { |
969 if ((changed & 1) == 1 && (state & HEIGHT_FLAG) == 0) { |
976 if ((changed & 1) == 1 && (state & HEIGHT_FLAG) == 0) { |
970 height = newHeight; |
977 height = newHeight; |
971 } |
978 } |
972 if ((changed & 2) == 2 && (state & WIDTH_FLAG) == 0) { |
979 if ((changed & 2) == 2 && (state & WIDTH_FLAG) == 0) { |